Script to create a frame with hyperlink

Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

Hi,

 

Apologies if this seems obvious, I don't know much about javascript.

 

I'm trying to write a script to create a rectangle with no fill on my current page, and hyperlink the frame. I managed to create the frame, but I don't understand how to hyperlink it.

 

Here's the bit that works:

var myDocument = app.activeWindow.activePage
var myFrame = myDocument.rectangles.add();
myFrame.geometricBounds = ["297mm", "210mm", "274.75mm", "0mm"];

 

How do I add the URL https://www.adobe.com/ to this frame?

 

Thanks in advance.

TOPICS
How to, Scripting

Views

137

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

1 Correct Answer

Adobe Community Professional , Aug 17, 2020
brianp311 Adobe Community Professional , Aug 17, 2020
Two hyperlinked frames can't have the same name. Setting "name:myURL" multiple times would cause this error. You can get around it by not setting the name, or by setting a custom name based on the frame's id, or a counter method, etc.    app.documents[0].hyperlinks.add(source, dest, {name:myURL + "_" source.id});    

Likes

Translate

Translate
Jump to answer Jump to answer
Adobe Community Professional ,
Aug 07, 2020

Copy link to clipboard

Copied

Hi there,

See my answer to the following discussion, it has pieces of code that you can integrate into your script. Give it a shot

https://community.adobe.com/t5/indesign/how-to-change-automatically-frame-with-hyperlink-text-into-h...

-Manan

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Aug 07, 2020

Copy link to clipboard

Copied

Thank you for your reply.

I don't really understand how Javascript works, so I really couldn't figure out what to extract from your comment.

However, I got a friend to help and eventually came up with this which worked:

 

 

var myDocument = app.activeWindow.activePage;
var myFrame = myDocument.rectangles.add();
myFrame.geometricBounds = ["297mm", "210mm", "274.75mm", "0mm"];

var myURL = "https://www.adobe.com"; 

var source = app.documents[0].hyperlinkPageItemSources.add(myFrame);
var dest = app.documents[0].hyperlinkURLDestinations.add(myURL);

app.documents[0].hyperlinks.add(source, dest, {name:myURL});

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Community Beginner ,
Aug 17, 2020

Copy link to clipboard

Copied

Sorry to resurrect this thread - I thought it was working well, but I've realised that if a similar hyperlinked frame already exists on another master page, the code won't work: "This name is already in use by another object - Source: app.documents[0].hyperlinks.add(sourcedest, {name:myURL});"

My understanding is that my code searches the entire document for a frame to add the hyperlink to, rather than the active page, but I don't know how to specify that. I tried "myDocument.hyperlinks.add(source, dest, {name:myURL});" but that doesn't work either. Sorry if it's really obvious!

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Adobe Community Professional ,
Aug 17, 2020

Copy link to clipboard

Copied

Two hyperlinked frames can't have the same name. Setting "name:myURL" multiple times would cause this error. You can get around it by not setting the name, or by setting a custom name based on the frame's id, or a counter method, etc. 

 

app.documents[0].hyperlinks.add(source, dest, {name:myURL + "_" source.id});

 

 

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
user10643867 AUTHOR LATEST
Community Beginner ,
Aug 18, 2020

Copy link to clipboard

Copied

Thank you! 

Your line of code was just missing a '+' before source.id it seems, now it works perfectly.

Likes

Translate

Translate

Report

Report
Reply
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more