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

Remove hyperlinks from an InDesign document

New Here ,
Jan 11, 2011 Jan 11, 2011

Copy link to clipboard

Copied

Hi!

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

Thanks!

TOPICS
Scripting

Views

8.1K

Translate

Translate

Report

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

Guru , 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();
        }
    }
}

Votes

Translate

Translate
Guru ,
Jan 11, 2011 Jan 11, 2011

Copy link to clipboard

Copied

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();
        }
    }
}

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Why not just:

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Wow, it was that simple!  Thanks guys! 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Harbs

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guru ,
Jun 06, 2014 Jun 06, 2014

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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