Skip to main content
Known Participant
May 14, 2025
Question

InDesign Javascript Hyperlink question

  • May 14, 2025
  • 2 replies
  • 1529 views

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

2 replies

Participating Frequently
May 14, 2025

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

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

—————————————————————————————Krommatine Systems — Makers of InDesign plugins, tools, and automations.
m1b
Community Expert
Community Expert
May 14, 2025

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

Participating Frequently
May 15, 2025

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). 

—————————————————————————————Krommatine Systems — Makers of InDesign plugins, tools, and automations.
Peter Kahrel
Community Expert
Community Expert
May 14, 2025

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.

Known Participant
May 14, 2025

Great! 👍

Thanks for the help Peter 🙂

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

Robert at ID-Tasker
Legend
May 14, 2025

@Nick37129562ryen

 

There is a separate HyperlinkTextDestinations collection:

 

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

 

Hyperlink and Bookmark can have a TextDestination.