...

View Full Version : Naming of created desktop shortcut



Scrabble
01-31-2007, 10:23 PM
Any help would be appreciated. I am having a problem with this script:

if( document.FullName == location.href ) {
alert( "The file is untitled." );
}
else {
WshShell = new ActiveXObject( "WScript.Shell" );
strDesktop = WshShell.SpecialFolders("Desktop");
ShellLink = WshShell.CreateShortcut(strDesktop + "\\" + (document.title) + ".lnk");
ShellLink.TargetPath = location.href;
ShellLink.WindowStyle = 1;
ShellLink.Description = "Shortcut to My File";
ShellLink.WorkingDirectory = strDesktop;
ShellLink.Save();
}


The script seems to generally work fine. However, it seems that it will not create a shortcut on the desktop to some websites (the same ones all of the time). I will list a couple of them below:

http://kodak.com/eknec/PageQuerier.jhtml?pq-path=2/6868&pq-locale=en_US&_requestid=6711
http://www.szgoto.com/doce/products_new.htm


...and then there is the case, like the one below, that one page will create a shortcut and another will not...

This will: http://www.lockergnome.com/nexus/windows/?where=here&s=open+links+in+new+window
This will not: http://www.lockergnome.com/nexus/windows/2006/09/05/survey-of-net-neutrality-editorials-blog-posts/

...and one more scenario -- two different sites create the same shortcut, thus the new shortcut replaces the old one...example below...

http://goto.manufacturer.globalsources.com/si/6008811716771/Showroom/point_id-3000000149681/catalog_id-2000000003844/showroom_type-ALL.htm?diffsupp=prodL4
http://goto.manufacturer.globalsources.com/si/6008811716771/CompanyProfile.htm

Again, any help would be appreciated. Thank you.

david_kw
02-01-2007, 02:24 AM
Again, I believe it is illegal characters in a windows file name. You need to replace or get rid of the illegal characters. If you wonder what is illegal try changing the name of an icon on your desktop. When I do that I get

A file cannot contain any of the following characters:
\ / : * ? " < > |

If you look at the document title for the kodak link you'll notice it has a | in it. Some of the other document titles look like they might be unicode which I don't believe windows can handle either.

Try this code to see if it lets you mark the kodak site.



if( document.FullName == location.href ) {
alert( "The file is untitled." );
}
else {
WshShell = new ActiveXObject( "WScript.Shell" );
strDesktop = WshShell.SpecialFolders("Desktop");
sName = document.title;
sName = sName.replace(/[^\w\d\s]/g, "");
if (sName.length > 30) sName = sName.substring(0, 60);
ShellLink = WshShell.CreateShortcut(strDesktop + "\\" + (sName) + ".lnk");
ShellLink.TargetPath = location.href;
ShellLink.WindowStyle = 1;
ShellLink.Description = "Shortcut to My File";
ShellLink.WorkingDirectory = strDesktop;
ShellLink.Save();
}


I don't know if that will be enough for all the pages but it might help.

david_kw

Scrabble
02-01-2007, 04:11 AM
Thank you david_kw. Yes, that fixed most of the problems. The changes had no effect on the one that created the same shortcut for two different websites. I think that is because the length limitation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum