Add Website Shortcut/Icon to Desktop?

I was wondering if it’s possible to make a link on my site so if a visitor clicked it, it would save an icon/shortcut to my website?

I know this can be done by right clicking in the page and selecting “Create Shortcut”, but I would like to make it so it was a regular hyperlink.

I came across this code [http://www.ca-osi.com/article.php?sid=107] but I can’t get it to work. Can somebody tell me what I’m doing wrong:

<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!-- Begin
document.writeln('Putting a shortcut on your desktopnn');

document.write("");

if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;

function AddFavLnk(loc, DispName, SiteURL) {
var Shor = Shl.CreateShortcut(loc + "" + DispName +".URL");
Shor.TargetPath = SiteURL;
Shor.Save();
}

function f() {
try {
a1=document.applets[0];
a1.setCLSID("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Shl = a1.GetObject();
a1.setCLSID("{0D43FE01-F093-11CF-8940-00A0C9054228}");
a1.createInstance();
FSO = a1.GetObject();
a1.setCLSID("{F935DC26-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Net = a1.GetObject();
try
{
var WF, Shor, loc;

WF = FSO.GetSpecialFolder(0);
if (language.indexOf('en') >-1) loc = WF + "desktop"; else
document.writeln('Unable to place a shortcut on your desktop');

AddFavLnk(loc, "ca-osi.com", "http://www.ca-osi.com");
document.writeln('A shortcut has been placed on your desktop');
}
catch(e) {}
}
catch(e) {}
}

function init() {
setTimeout("f()", 1000);
}

init();
// End -->
</script>
</head>

<body>
<a href="AddFavLnk();">Add to Desktop</a>
</body>
</html>

My first thought after trying the code is that this line:

<a href="AddFavLnk();">Add to Desktop</a>

should read:

<a href=# onClick="AddFavLnk()">Add to Desktop</a>

or something like that.

Alternatively, it’s probably possible to put something like:

<a href="javascript:AddFavLnk();">Add to Desktop</a>

but I’ve never played around with that kind of call so syntactically it may be incorrect.

Having said all that, I’m still getting a problem with “Shl” being undefined, so I’ll delve a little deeper into the code and try work out why that is.

Andy

Disclaimer:
I think that there’s a better way of writing “href=#” but I can’t recall it right now.

Does anybody know how to get this script to work?

Originally posted by JohnSaunders
I came across this code [http://www.ca-osi.com/article.php?sid=107] but I can’t get it to work. Can somebody tell me what I’m doing wrong:

Forgot this line?
document.write(“<APPLET height=0 width=0 code=com.ms.activeX.ActiveXComponent></APPLET>”);

OK…I tried the code below but I still couldnt’ get it to work. I tried it with and without the link. When clicking the link, I still got the Shl not defined error.

Does anybody else have any ideas?

<html>
<head>
<script language="JavaScript" type="text/JavaScript">
<!-- Begin
document.writeln('Putting a shortcut on your desktopnn');

document.write("<APPLET height=0 width=0 code=com.ms.activeX.ActiveXComponent></APPLET>");

if (navigator.appName == 'Netscape')
var language = navigator.language;
else
var language = navigator.browserLanguage;

function AddFavLnk(loc, DispName, SiteURL) {
var Shor = Shl.CreateShortcut(loc + "" + DispName +".URL");
Shor.TargetPath = SiteURL;
Shor.Save();
}

function f() {
try {
a1=document.applets[0];
a1.setCLSID("{F935DC22-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Shl = a1.GetObject();
a1.setCLSID("{0D43FE01-F093-11CF-8940-00A0C9054228}");
a1.createInstance();
FSO = a1.GetObject();
a1.setCLSID("{F935DC26-1CF0-11D0-ADB9-00C04FD58A0B}");
a1.createInstance();
Net = a1.GetObject();
try
{
var WF, Shor, loc;

WF = FSO.GetSpecialFolder(0);
if (language.indexOf('en') >-1) loc = WF + "desktop"; else
document.writeln('Unable to place a shortcut on your desktop');

AddFavLnk(loc, "ca-osi.com", "http://www.ca-osi.com");
document.writeln('A shortcut has been placed on your desktop');
}
catch(e) {}
}
catch(e) {}
}

function init() {
setTimeout("f()", 1000);
}

init();
// End -->
</script>
</head>

<body>
<a href=# onClick="AddFavLnk()">Add to Desktop</a>
</body>
</html>