SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    John Saunders

  2. #2
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:

    Code:
    <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>
    John Saunders

  3. #3
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My first thought after trying the code is that this line:
    Code:
    <a href="AddFavLnk();">Add to Desktop</a>
    should read:
    Code:
    <a href=# onClick="AddFavLnk()">Add to Desktop</a>
    or something like that.

    Alternatively, it's probably possible to put something like:
    Code:
    <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.
    From the English nation to a US location.

  4. #4
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anybody know how to get this script to work?
    John Saunders

  5. #5
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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>");

  6. #6
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

    Code:
    <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>
    John Saunders


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •