1、首先js添加到桌面fetchAPI提供了一个JavaScript接口。
2、其次用于访问和操纵HTTP管道的部分。
3、最后只要浏览器支持js就能运行,规避了IE限制。
一般来说直接用Javascript创建的话只支持IE,代码如下:
functionCreateShortcut() {try{
varfso = newActiveXObject("Scripting.FileSystemObject")
varshell = newActiveXObject("WScript.Shell")
vartagFolder = shell.SpecialFolders("Desktop")
if(!fso.FolderExists(tagFolder )) {
fso.CreateFolder(tagFolder)
}
if(!fso.FileExists(tagFolder + "\\乐猪软件.lnk")) {
varWshSysEnv = shell.Environment("Process")
iLocal = (WshSysEnv.Item("SystemRoot") +"\\1.ico") //下载到C:\windows\1.ico
iRemote = ("/Images/2.ico") //先下载图标文件,再用自定义图标把首页的图标地址替换
varxPost = newActiveXObject("Microsoft.XMLHTTP")
xPost.Open("GET", iRemote, 0)
xPost.Send()
varsGet = newActiveXObject("ADODB.Stream")
sGet.Mode = 3
sGet.Type = 1
sGet.Open()
sGet.Write(xPost.ResponseBody )
sGet.SaveToFile( iLocal,2)
varlink = shell.CreateShortcut(tagFolder + "\\编程入门管理系统.lnk")
link.Description = "打开基本软件的快捷方式"
link.Hotkey = "Ctrl+Alt+e"
link.TargetPath = "http://www.lezhu99.com/"
link.IconLocation=iLocal
link.WindowStyle = 3
link.WorkingDirectory = "c:\\blah"
link.Save()
alert("恭喜!快捷方式创建成功!")
}
}
catch(ex){
alert("快捷方式创建失败,可能浏览器不支持!")
}
}
为了支持所有浏览器,我们可以用动态语言来做。
1.php代码:
<?php$Shortcut = "[InternetShortcut]
URL=http://www.0356sh.com
IconFile=http://www.0356sh.com/favicon.ico
IconIndex=0
HotKey=1613
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2"
header("Content-Type: application/octet-stream")
header("Content-Disposition: attachment filename=晋城生活服务.url")
echo $Shortcut
?>
HTML中的代码:
<a href="1.php" target="_blank">创建桌面快捷方式</a>