Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

• Add clickable URL into a javascript created palette

Enthusiast ,
Feb 27, 2023 Feb 27, 2023

Hello -

 

I would like to add an URL (clickable)

into a small javascript created palette (script is located into the 'Startup Scripts" foler).

The text appears but it isn't clickable.

I (of course) missed something here any idea what?

 

Thank you  🙂

 

#target Illustrator
#targetengine main

var myWindow = new Window ("palette");
var myMessage = myWindow.add ("statictext");
	myText = "EAN";
	myMessage.text = "<a href='https://www.free-barcode-generator.net/ean-13/'>" + myText + "</a>";	// Was "Hello, world!";
	myWindow.show();

 

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Expert , Feb 27, 2023 Feb 27, 2023

@Sergey Osokin has a great little function he created called `openURL()`. You can just add it at the bottom of your script and then activate it with an event listener on your `myMessage` element.

 

// ...
myMessage.addEventListener('mousedown', function () {
    openURL('https://github.com/creold');
  })

/**
* Open link in browser - Sergey Osokin
* https://community.adobe.com/t5/user/viewprofilepage/user-id/11040189
* @param {string} url - Website adress
*/
function openURL(url) {
  var html = ne
...
Translate
Community Expert , Feb 28, 2023 Feb 28, 2023

Ha, this is exactly what I was going to suggest... When I tried this in the past the results were inconsistent at best (due to fonts and system type) as you mention. So, I typically just use blue coloring (HTML default for links) or buttons as most people notice those as being clickable.

Translate
Adobe
LEGEND ,
Feb 27, 2023 Feb 27, 2023

You need to initialize a socket connection. URLs get not converted automatically for security reasons.

 

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 27, 2023 Feb 27, 2023

Hi Mylenium -

 

Thx for your reply.

I'm not familiar with "socket connection".

Any example that could really helpin this context?

 

Thank you.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 27, 2023 Feb 27, 2023

@Sergey Osokin has a great little function he created called `openURL()`. You can just add it at the bottom of your script and then activate it with an event listener on your `myMessage` element.

 

// ...
myMessage.addEventListener('mousedown', function () {
    openURL('https://github.com/creold');
  })

/**
* Open link in browser - Sergey Osokin
* https://community.adobe.com/t5/user/viewprofilepage/user-id/11040189
* @param {string} url - Website adress
*/
function openURL(url) {
  var html = new File(Folder.temp.absoluteURI + '/aisLink.html');
  html.open('w');
  var htmlBody = '<html><head><META HTTP-EQUIV=Refresh CONTENT="0; URL=' + url + '"></head><body> <p></body></html>';
  html.write(htmlBody);
  html.close();
  html.execute();
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 27, 2023 Feb 27, 2023

@jduncan Thanks for sharing. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2023 Feb 28, 2023

Hey  🙂

 

Thanks a lot it works like a charm…

Thanks also to Sergey  🙂

 

Have a great day

 

 

- Dimitri

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Feb 28, 2023 Feb 28, 2023

Hello again…  🙂

 

I wonder if we could displace/move the new created UI window to a specific location on the screen?

 

OK… I finally make it work  🙂

myWindow.frameLocation = [ 1950, 400 ];
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 28, 2023 Feb 28, 2023

Does anyone know how (if it is possible) to make the static text underlined, so as to resemble a hyperlink? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2023 Feb 28, 2023

Did you try using underlined text when noting the text?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 28, 2023 Feb 28, 2023

@Larry G. Schneider  I'm not quite sure what you meant by "noting the text", but I tried using Unicode to do the underlining.  The results vary between fonts and, I suspect, between AI versions.  This is what I get with the default ScriptUI font in CS6 (you can see gaps after m's):

 

femkeblanco_0-1677618759898.pngexpand image

 

var s1 = "https://www.abcdefghijklmnopqrstuvwxyz.com/", s2 = "";
for (var i = 0; i < s1.length; i++) s2 += "\u035F" + s1[i];
var w = new Window("dialog");
var st = w.add("statictext");
	  st.text = s2;
    st.graphics.foregroundColor = st.graphics.newPen (
        w.graphics.PenType.SOLID_COLOR, [0, 0, 1], 1);
    st.graphics.font = ScriptUI.newFont ("dialog", "Regular", 20);
    st.helpTip = "Click"
w.show();

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 28, 2023 Feb 28, 2023
LATEST

Ha, this is exactly what I was going to suggest... When I tried this in the past the results were inconsistent at best (due to fonts and system type) as you mention. So, I typically just use blue coloring (HTML default for links) or buttons as most people notice those as being clickable.

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