Skip to main content
Participating Frequently
January 11, 2011
Answered

Remove hyperlinks from an InDesign document

  • January 11, 2011
  • 2 replies
  • 9006 views

Hi!

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

Thanks!

This topic has been closed for replies.
Correct answer Kasyan Servetsky
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();
        }
    }
}

2 replies

Inspiring
September 10, 2018

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.

Kasyan Servetsky
Kasyan ServetskyCorrect answer
Legend
January 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();
        }
    }
}
TᴀW
Legend
January 11, 2011

Why not just:

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

Visit www.id-extras.com for powerful InDesign scripts that save hours of work — automation, batch tools, and workflow boosters for serious designers.
Participating Frequently
January 12, 2011

Wow, it was that simple!  Thanks guys!