Skip to main content
Inspiring
December 30, 2021
Answered

How to validate whether Hyperlink already present or not in Indesign using Javascript?

  • December 30, 2021
  • 3 replies
  • 917 views

Is there any way to validate the Hyperlinks already added in the indesign document.

This topic has been closed for replies.
Correct answer Charu Rajput

Hi,

Below is the snippet that will help you to tell whether hyperlink exists or not.

var doc = app.activeDocument;
var _hyperLink = doc.hyperlinks.itemByName('test');
if(_hyperLink.isValid)
    alert("Exists");
else
    alert("Not exists");

 

Assuming, hyperlink with name "test" exists in teh indesig document.

3 replies

brian_p_dts
Community Expert
Community Expert
December 30, 2021

Can you be more specific? If you want to check if a block of Text has hyperlinks, you can use myText.findHyperlinks(), which will return an array of all hyperlinks in that text (array length can be 0)

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
December 30, 2021

Hi,

Below is the snippet that will help you to tell whether hyperlink exists or not.

var doc = app.activeDocument;
var _hyperLink = doc.hyperlinks.itemByName('test');
if(_hyperLink.isValid)
    alert("Exists");
else
    alert("Not exists");

 

Assuming, hyperlink with name "test" exists in teh indesig document.

Best regards
Sunil Yadav
Legend
February 12, 2022

This would do the trick.

Willi Adelberger
Community Expert
Community Expert
December 30, 2021

Look into the Hyperlink panel.