Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove hyperlinks from an InDesign document

New Here ,
Jan 11, 2011 Jan 11, 2011

Hi!

Is there a script command that I can use to change hyperlinks of a document to just regular text?

Thanks!

TOPICS
Scripting
8.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Jan 11, 2011 Jan 11, 2011
var gDoc = app.activeDocument;
RemoveHyperLinks();

function RemoveHyperLinks() {
    if (gDoc.hyperlinks.length > 0){
        for (var i = gDoc.hyperlinks.length-1; i >= 0; i--) {
            gDoc.hyperlinks.remove();
        }
    }
}
Translate
Valorous Hero ,
Jan 11, 2011 Jan 11, 2011
var gDoc = app.activeDocument;
RemoveHyperLinks();

function RemoveHyperLinks() {
    if (gDoc.hyperlinks.length > 0){
        for (var i = gDoc.hyperlinks.length-1; i >= 0; i--) {
            gDoc.hyperlinks.remove();
        }
    }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Jan 11, 2011 Jan 11, 2011

Why not just:

app.activeDocument.hyperlinks.everyItem().remove()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2011 Jan 11, 2011

Wow, it was that simple!  Thanks guys! 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2011 Jan 11, 2011

IIRC, you need to remove the hyperlink source and hyperlink destination as well...

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2011 Jan 11, 2011

Hi Harbs!

It doesn't remove those as well?  Is that why when I try to turn them back to hyperlinks, it does not work?  How do I go about doing that?  Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 11, 2011 Jan 11, 2011

It depends what you are trying to do.

If you used text sources and destinations and you want to remove them all, this should do the job:

app.activeDocument.hyperlinkTextDestinations.everyItem().remove()

app.activeDocument.hyperlinkTextSources.everyItem().remove()

Otherwise, you'd want to loop through the hyperlinks and remove the destinations and sources as you go...

Harbs

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 12, 2011 Jan 12, 2011

Thanks Harbs!

Yes, I did use text sources and destinations. Now I can remove the hyperlinks and create them again with no problem at all!

Thanks again, guys!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2012 May 20, 2012

Thank you, Harbs!

Your script has enabled me to strip out problematic hyperlinks imported from Word. After numerous unsuccessful attempts, I can now successfully export the document to epub.

I am most grateful.

Marie

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 03, 2014 Jun 03, 2014

Hi Harbs,

I've encountered this issue in a document but am not familiar with scripting. How would I use these lines?

app.activeDocument.hyperlinkTextDestinations.everyItem().remove()

app.activeDocument.hyperlinkTextSources.everyItem().remove()

A thousand thank you's!

Amanda

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jun 06, 2014 Jun 06, 2014

Simply run this script:

app.activeDocument.hyperlinks.everyItem().remove();

app.activeDocument.hyperlinkTextDestinations.everyItem().remove();

app.activeDocument.hyperlinkTextSources.everyItem().remove();

It deletes all hyperlinks, text anchors (destinations) and text sources.

— Kas

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 10, 2018 Sep 10, 2018
LATEST

I realise this is an old thread, but people (like myself) stumble onto these things when Googling for answers, so I thought it worth adding to the answers here…

It's not always necessary to delete every object (hyperlink, source and destination) in order to completely remove a hyperlink. In fact, if you're trying to remove individual hyperlinks this way, you'll most likely end up trying to access non-existing objects and crash your script.

The short answer is, removing the `hyperlinkTextSource` object is, in most cases, all you need to do. For a more in-depth answer, see my answer on Stack Overflow.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines