Skip to main content
Belyakov
Inspiring
March 22, 2019
Answered

How to convert text selection into Hyperlink?

  • March 22, 2019
  • 2 replies
  • 2375 views

Mytext1, mytext2, mytext3.

I'd like to select mytext2 and convert it to hyperlink (like as by context menu: Hyperlink - New hyperlink from URL.)

Is it possible?

Thanks.

This topic has been closed for replies.
Correct answer Manan Joshi

Something like the following should work, run the code with a text selection and it should create the hyperlink on it. Change the app.selection[0] to the object of the text that you might have in your actual code

var source = app.documents[0].hyperlinkTextSources.add(app.selection[0])

var dest = app.documents[0].hyperlinkURLDestinations.add("http://"+ app.selection[0].contents)

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

-Manan

2 replies

Belyakov
BelyakovAuthor
Inspiring
March 22, 2019

Many thanks!

Manan JoshiCommunity ExpertCorrect answer
Community Expert
March 22, 2019

Something like the following should work, run the code with a text selection and it should create the hyperlink on it. Change the app.selection[0] to the object of the text that you might have in your actual code

var source = app.documents[0].hyperlinkTextSources.add(app.selection[0])

var dest = app.documents[0].hyperlinkURLDestinations.add("http://"+ app.selection[0].contents)

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

-Manan

-Manan