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

Links JavaScript

Explorer ,
May 02, 2016 May 02, 2016

Hi guys!

Please help me with this...

How can I go to a website using javascript inside Illustrator?

I have a little button and would like when I do click, open the browser

and go to the website.

Many thanks guys!

TOPICS
Scripting
1.4K
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 1 Correct answer

Valorous Hero , May 03, 2016 May 03, 2016

From this thread:

Re: Link to a web page from AI javascript?

16. Re: Link to a web page from AI javascript?

Muppet MarkRockstar

As it would appear to work mac/pc then I would just wrap it to use like so… I've changed the location to the system temporary junk… Out of sight, and it should get cleaned out at system restart me thinks… I did try f.remove() but that would appear to take place faster than the file can be evoked so I removed it. I doubt very much the size

...
Translate
Adobe
Enthusiast ,
May 03, 2016 May 03, 2016

in an HTML 5 panel

var csi = new CSInterface()

csi.openURLInDefaultBrowser("url");

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
Valorous Hero ,
May 03, 2016 May 03, 2016

From this thread:

Re: Link to a web page from AI javascript?

16. Re: Link to a web page from AI javascript?

Muppet MarkRockstar

As it would appear to work mac/pc then I would just wrap it to use like so… I've changed the location to the system temporary junk… Out of sight, and it should get cleaned out at system restart me thinks… I did try f.remove() but that would appear to take place faster than the file can be evoked so I removed it. I doubt very much the size of these would ever be a problem…

  1. openURL( 'www.google.com' ); 
  2.  
  3. function openURL( address ) { 
  4.  
  5.           var f = File( Folder.temp + '/aiOpenURL.url' ); 
  6.             
  7.           f.open( 'w' ); 
  8.             
  9.           f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' ); 
  10.             
  11.           f.close(); 
  12.             
  13.           f.execute(); 
  14.    
  15. }; 
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 ,
May 03, 2016 May 03, 2016

wonder if it is possible to write a batch rather then a .url

and have the batch file trigger something like a callback.

I just cant think of the best way to get the batch file to trigger the callback.

but as this will always overwrite the last .url file, I don't see the point.

it is just 1 file, stashed away in some location most users don't even know exists, and its a total of about 1kB.

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
Explorer ,
May 09, 2016 May 09, 2016

Many thanks guys! Worked like a charm xD

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
Engaged ,
Jan 04, 2022 Jan 04, 2022

Hello, I tried the javascript above. But it's not working on (my) Mac. So I created a solution, that will run on both OS:

 

// Javascript for Adobe Illustrator 26.0.2 or older
// tested on macOS 10.15.7 with Web browser Safari 15.2
// testet on Windows 10 with Web browser Edge 96

var f = new File();

function openURL( address ) { 
    var vPathApp = ""+ app.path; // trick: use an empty string to convert it to a string that AI-JS can read
    if (vPathApp.indexOf("Application")> 0) { // it's a Mac, do the Mac magic
        f = File( Folder.temp + "/aiOpenURL.webloc" ); 
        f.open( "w" ); 
        f.write("<?xml version='1.0' encoding='UTF-8'?>"+"\n");
        f.write("<!DOCTYPE plist PUBLIC '-//Apple//DTD PLIST 1.0//EN' 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>"+"\n");
        f.write("<plist version='1.0'><dict><key>URL</key>"+"\n");
        f.write("<string>https://"+ address + "</string>"+"\n");
        f.write("</dict></plist>"+"\n");
        f.close(); 
    }
    else { // it's a PC, do the PC stuff
        f = File( Folder.temp + "/aiOpenURL.url" ); 
        f.open( "w" ); 
        f.write( '[InternetShortcut]' + '\r' + 'URL=http://' + address + '\r' ); 
        f.close(); 
    }
    f.execute(); 
}; 

// MAIN script
openURL( "www.google.de");
try { f.remove(); } catch(e) {} // try to delete the aiOpenURL-file 
// end of script

And it will remove the temp file called "aiOpenURL..." 🙂

 

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
Valorous Hero ,
Jan 06, 2022 Jan 06, 2022

Another cross platform solution could use embedded javascript in a dynamic HTML file to navigate to a preferred location. I've been using this technique for years after experiments around this post, and in retrospect I've only used the web-link-shortcut method just a few times.

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 ,
May 28, 2022 May 28, 2022

This is great, just what I was looking for after having the same Mac trouble with the original answer. Thank you. Just so you know, an easy way to find whether Mac or Windows is the property all the apps have Folder.fs

if (Folder.fs == "Macintosh" {
    // script is running on a mac
} else if (Folder.fs == "Windows" {
    // script is running on windows
}

 

William Campbell
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 ,
May 29, 2022 May 29, 2022
LATEST

there's also 

 

alert($.os); // Result: Windows 7/64 6.2  (32-bit emulation)
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