|
保存到桌面、设为桌面的代码【js、php、asp】-it论坛-计算机论坛
js方法- <script language="JavaScript">
- function toDesktop(sUrl,sName)
- {
- try
- {
- var WshShell = new ActiveXObject("WScript.Shell");
- var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "//" + sName + ".url");
- oUrlLink.TargetPath = sUrl;
- oUrlLink.Save();
- }
- catch(e)
- {
- alert("当前IE安全级别不允许操作!请设置后在操作.");
- }
- }
- </script>
- <input name="btn" type="button" id="btn" value="创建的快捷方式" onClick="toDesktop('http://mall.agoit.com/','IT商城'">创建的快捷方式</a>
复制代码 仿开心网的设为桌面
- public function shortcutAction()
- {
- $this->_helper->layout->disableLayout();
- $this->_helper->viewRenderer->setNoRender( true );
- $url = site_url();
- $Shortcut = "
- [InternetShortcut]
- URL=".$url."
- IDList=IconIndex=43
- IconFile=/favicon.ico
- HotKey=1626
- [{000214A0-0000-0000-C000-000000000046}]
- Prop3=19,2";
- Header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=开心网.url");
- echo $Shortcut;
- }
复制代码 1、将下面的代码保存为文件,shorturl.asp。记得修改第二行及第四行内的url名称和网址。- <%
- Response.ContentType="APPLICATION/OCTET-STREAM"
- Response.AddHeader "Content-Disposition","attachment;filename="&"IT商城.url"
- Response.Write("[InternetShortcut]")&Chr(13)
- Response.Write("URL=http://mall.agoit.com")&Chr(13)
- Response.Write("IDList=")&Chr(13)
- Response.Write("[{000214A0-0000-0000-C000-000000000046}]")&Chr(13)
- Response.Write("Prop3=19,2")&Chr(13)
- Response.End
- %>
复制代码 2、将该文件上传至网站根目录。
3、在网站根目录上传Favicon.ico文件,有这个文件,保存的链接才会有图标显示。
4、在网站调用页面添加如下代码即可。- <a href='http://mall.agoit.com/shorturl.asp'>桌面图标</a>
复制代码 另附PHP代码,大家可以尝试一下,保存成shorturl.php即可,调用方式同asp。- <?php
- $Shortcut = "[InternetShortcut]
- URL=http://mall.agoit.com/
- IDList=
- [{000214A0-0000-0000-C000-000000000046}]
- Prop3=19,2
- ";
- Header("Content-type: application/octet-stream");
- header("Content-Disposition: attachment; filename=IT商城.url;");
- echo $Shortcut;
- ?>
复制代码 本文摘自:http://blog.csdn.net/coklo/article/details/6269289
|
|