Copy link to clipboard
Copied
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!
From this thread:
Re: Link to a web page from AI javascript?
Muppet Mark Dec 8, 2012 12:41 PM (in response to W_J_T)
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
...Copy link to clipboard
Copied
in an HTML 5 panel
var csi = new CSInterface()
csi.openURLInDefaultBrowser("url");
Copy link to clipboard
Copied
From this thread:
Re: Link to a web page from AI javascript?
Muppet Mark Dec 8, 2012 12:41 PM (in response to W_J_T)
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…
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Many thanks guys! Worked like a charm xD
Copy link to clipboard
Copied
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..." 🙂
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
Copy link to clipboard
Copied
there's also
alert($.os); // Result: Windows 7/64 6.2 (32-bit emulation)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now