网页创建快捷方式到桌面多种方法
我们会看到很多的网站不但有设置首页,加入收藏同时还有一个加到桌面快捷方式的功能,下面我来给大家介绍网页创建快捷方式到桌面多种方法介绍,有需要的朋友可参考.
最简单的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("请点击弹出对话框的:是 ");
-
- }
-
- }
-
- </script>
-
- <input name="btn" type="button" id="btn" value="把百度创建快捷方式到桌面" onClick="toDesktop('http://www.phpfensi.com/','百度一下,你就知道!')">
-
- <input name="btn" type="button" id="btn" value="C盘" onClick="toDesktop('file://C:','C盘')">
不足:这样做如果浏览器做了安全设置我们是不能使用上面的方法的,写php程序的朋友可能也知道一种办法,代码如下:
- <?php
- $Shortcut = "[InternetShortcut]
-
- URL=http:
-
- IconFile=http:
-
- 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;
-
- ?>
- <a href="">发送到桌面</a>
asp.net程序员可能也知道如下代码:
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class CreateShortcut : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
-
-
-
-
-
- private void CreateShortcut(string Title, string URL)
- {
- string strFavoriteFolder;
-
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
-
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
-
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "\链接";
- CreateShortcutFile(Title, URL, strFavoriteFolder);
-
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
- }
-
-
-
-
-
-
- private void CreateShortcutFile(string Title, string URL, string SpecialFolder)
- {
-
- System.IO.StreamWriter objWriter = System.IO.File.CreateText(SpecialFolder + "\" + Title + ".url");
-
- objWriter.WriteLine("[InternetShortcut]");
- objWriter.WriteLine("URL=" + URL);
-
- objWriter.Close();
- }
- private void btnShortcut_Click(object sender, System.EventArgs e)
- {
- CreateShortcut("php粉丝网", http:
- }
- }