Skip to main content
Known Participant
May 14, 2025 2:57 PM UTC
Question

InDesign Javascript Hyperlink question

Hi Everyone,

 

Please can someone help, is there a way of checking if a word has a hyperlink to a Text Anchor attached to it? I've written a script to give me a list of all the words that have a certain character style. What I'm trying to do is check each word for a hyperlink.

I've been digging down on the properties of a word but as yet I've not found what I'm looking for.

Thanks

21 replies

Vamitul - ks
Inspiring
May 14, 2025 4:06 PM UTC

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Text.html#d1e461232__d1e468837

`text.findHyperlinks()` will return any hyperlinTextSource in it, but it can get slow.

Translate
Krommatine Systems: InDesign plugins, tools, and automations.
m1b
Community Expert
Community Expert
May 14, 2025 5:37 PM UTC

Hi @Vamitul - ks that is my usual approach and I haven't noticed it being slow. Are you sure that the slowness wasn't caused by something else? @Peter Kahrel is that why you do the looping?

- Mark

Translate
Vamitul - ks
Inspiring
May 15, 2025 7:18 AM UTC

Behind the scenes, findHyperlinks is also looping through the hyperlink objects. It's closer to the machine because it issuing the internal db structure for it, but it's still a loop. 

Depending on the number of words that need to be checked, gathering all the hyperlink destinations and sources up front (more precisely, the `.sourceText` and `.destinationText` properties of them) and then checking if each of the words is part of the text can be a lot more effective. But testing if a Text object contains another Text object can be surprisingly complex (personally, I'd use resolved object specifiers for it). 

Translate
Krommatine Systems: InDesign plugins, tools, and automations.
Peter Kahrel
Community Expert
Community Expert
May 14, 2025 3:07 PM UTC

You'd go about it like this:

1. Get the word's parent story and its index (i.e. its position in a story).

2. Get all hyperlinks, go through their sources until you get a source whose parent story and index coincide with those of your words.

Translate
Known Participant
May 14, 2025 3:42 PM UTC

Great! 👍

Thanks for the help Peter 🙂

I was hoping there might be a property of the word I could use.

Translate
Robert at ID-Tasker
Legend
May 14, 2025 9:15 PM UTC

@Nick37129562ryen

 

There is a separate HyperlinkTextDestinations collection:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#HyperlinkTextDestinations.html

 

Hyperlink and Bookmark can have a TextDestination.

 

Translate