Click to See Complete Forum and Search --> : Create Shortcut on Dekstop via Javascript
rfaizal
09-06-2005, 08:42 PM
Hi,
I'm currently testing a feature that is enabling a shortcut on the desktop. However, I'm stuck at selecting the icon for the shortcut as by default it will show the IE icon. Can anyone help me on this. This is the coding created for the shortcut
<script language="Javascript">
var WshShell = new ActiveXObject("WScript.Shell");
strDesktop = WshShell.SpecialFolders("Desktop");
var oShellLink = WshShell.CreateShortcut(strDesktop + "\\shorcut.url");
oShellLink.TargetPath = "http://myurl.com";
oShellLink.Save();
</script>
:confused:
Stone_Man
09-13-2005, 07:54 AM
Simply name your icon "favicon.ico" and place it in your root directory. :cool:
felgall
09-13-2005, 04:53 PM
You should place that code inside of
if (ActiveXObject) {}
in order to avoid errors in browsers that are not IE running on Windows.
Ultimater
09-13-2005, 05:32 PM
Here's a helpful link to convert your BMPs, PNGs, etc into ICOs FOR FREE! and without downloading software!
http://www.html-kit.com/e/favicon.cgi
After you select a picture from your hard-drive and hit the "Generate Favicon.ico" buttoon
to save the ICO file to your desktop, just click the "download favicon" button and it will download to your desktop as a ZIP file containing both a PNG format preview of your ICO and the actual ICO along with a readme.
Enjoy!
zencoder
09-15-2006, 01:58 PM
(1) If you want to add a true shortcut in IE, you can create a text file with a .URL extension with its content in INI file format.
[InternetShortcut]
URL=http://www.webdeveloper.com
IconIndex=0
IconFile=C:\MyFolder\MyProgram.exe
-------
The icon file can be a .ico or a .exe with an embedded icon.
Just a guess but to add an icon to your existing code (your code creates the .url file) the following example is from the msdn library (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/7b956233-c1aa-4b59-b36d-f3e97a9b02f0.asp):
<script language="JScript">
var WshShell = WScript.CreateObject("WScript.Shell");
strDesktop = WshShell.SpecialFolders("Desktop");
var oShellLink = WshShell.CreateShortcut(strDesktop + "\\Shortcut Script.lnk");
oShellLink.TargetPath = WScript.ScriptFullName;
oShellLink.WindowStyle = 1;
oShellLink.Hotkey = "CTRL+SHIFT+F";
oShellLink.IconLocation = "notepad.exe, 0";
oShellLink.Description = "Shortcut Script";
oShellLink.WorkingDirectory = strDesktop;
oShellLink.Save();
</script>
(2) If you want to add a bookmark in the favorites folder I suggest reading this article: http://scriptasylum.com/tutorials/bookmark.html. A single java script function and an input button should get you there.
<script language="Javascript">
function setBookmark(url,str){
if(str=='')str=url;
if (document.all)window.external.AddFavorite(url,str);
else alert('Press CTRL and D to add a bookmark to:\n"'+url+'".');
}
</script>
<input type="button" value="Add to Favorites"
onclick="setBookmark( self.location.href , document.title )">
-- Britton LaRoche
zencoder
09-15-2006, 03:02 PM
This handy script adds a bookmark link for mozilla opera and firefox:
<script language="JavaScript1.2" type="text/javascript">
function AddBookmarkLink() {
title = "Webpage Title";
url = "Webpage URL";
if (window.sidebar) {
// Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) {
// IE Favorite
window.external.AddFavorite( url, title);
} else if(window.opera && window.print) {
// Opera Hotlist
return true;
}
}
if (window.external) {
document.write('<a href ="javascript:AddBookmarkLink()");">Add to Favorites</a>');
} else if (window.sidebar) {
document.write('<a href = "javascript:AddBookmarkLink()");">Bookmark Page</a>');
} else if (window.opera && window.print) {
document.write('<a href = "javascript:AddBookmarkLink()");">Add Bookmark</a>');
}
</script>
Kravvitz
09-16-2006, 12:13 AM
Check out this: The Ultimate Add Bookmark Script (http://www.dynamicsitesolutions.com/javascript/add_bookmark/)
zencoder, please read Guidelines and Suggestions for Posting on Web Development Forums (http://www.dynamicsitesolutions.com/other/forum_posting_guidelines/).
zencoder
09-18-2006, 11:43 AM
Kravitz,
Check out this: The Ultimate Add Bookmark Script (http://www.dynamicsitesolutions.com/javascript/add_bookmark/)
Now that is a nice script! I looked at the license, we able to use that script in commercial applications?
zencoder, please read Guidelines and Suggestions for Posting on Web Development Forums (http://www.dynamicsitesolutions.com/other/forum_posting_guidelines/).
I am new. Forgive me, was I cross posting? I found this link looking for a decent bookmark javascript example. I found the answer to a windows short cut and I thought I'd try to help answer both questions.
Kravvitz
09-19-2006, 12:14 PM
Now that is a nice script! I looked at the license, we able to use that script in commercial applications?
The license says that you can negotiate for its use in commercial applications -- you would probably need to pay a fee.
I am new. Forgive me, was I cross posting?
No, I linked to that because you didn't use the [code] tags.
zencoder
09-20-2006, 11:09 AM
I linked to that because you didn't use the [code] tags.
Sweet! You rock Kravitz! :D
Thanks for the tip!