我們會看到很多的網(wǎng)站不但有設(shè)置首頁,加入收藏同時還有一個加到桌面快捷方式的功能,下面我來給大家介紹網(wǎng)頁創(chuàng)建快捷方式到桌面多種方法介紹,有需要的朋友可參考.
最簡單的js實現(xiàn)方法,代碼如下:
- <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="把百度創(chuàng)建快捷方式到桌面" onClick="toDesktop('http://m.survivalescaperooms.com/','百度一下,你就知道!')">
- <input name="btn" type="button" id="btn" value="C盤" onClick="toDesktop('file://C:','C盤')">
不足:這樣做如果瀏覽器做了安全設(shè)置我們是不能使用上面的方法的,寫php程序的朋友可能也知道一種辦法,代碼如下:
- <?php
- $Shortcut = "[InternetShortcut]
- URL=http://m.survivalescaperooms.com
- IconFile=http://m.survivalescaperooms.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;
- ?>
- <a href="">發(fā)送到桌面</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)
- {
- }
- /// <summary>
- /// 創(chuàng)建快捷方式
- /// </summary>
- /// <param name="Title">標(biāo)題</param>
- /// <param name="URL">URL地址</param>
- private void CreateShortcut(string Title, string URL)
- {
- string strFavoriteFolder;
- // “收藏夾”中 創(chuàng)建 IE 快捷方式
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
- // “ 桌面 ”中 創(chuàng)建 IE 快捷方式
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
- // “ 鏈接 ”中 創(chuàng)建 IE 快捷方式
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "/鏈接";
- CreateShortcutFile(Title, URL, strFavoriteFolder);
- //「開始」菜單中 創(chuàng)建 IE 快捷方式
- strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
- CreateShortcutFile(Title, URL, strFavoriteFolder);
- }
- /// <summary>
- /// 創(chuàng)建快捷方式
- /// </summary>
- /// <param name="Title">標(biāo)題</param>
- /// <param name="URL">URL地址</param>
- /// <param name="SpecialFolder">特殊文件夾</param>
- private void CreateShortcutFile(string Title, string URL, string SpecialFolder)
- {
- // Create shortcut file, based on Title
- System.IO.StreamWriter objWriter = System.IO.File.CreateText(SpecialFolder + "/" + Title + ".url");
- // Write URL to file
- objWriter.WriteLine("[InternetShortcut]");
- objWriter.WriteLine("URL=" + URL);
- // Close file
- objWriter.Close();
- }
- private void btnShortcut_Click(object sender, System.EventArgs e)
- {
- CreateShortcut("php粉絲網(wǎng)", http://m.survivalescaperooms.com);
- }
- }
新聞熱點
疑難解答