把网页网址保存/下载到桌面的4中语言源码
将网址加入收藏夹,或者直接将网址保存到桌面快捷键,都是可以方便用户访问网站的功能。加入收藏夹现在很多浏览器都不支持了,需要手动添加,但是下载到桌面还是比较好用的,现在把源码分享给大家!
1、最简单的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 type="button" value="把百度创建快捷方式到桌面" onClick="toDesktop('http://www.baidu.com/','百度一下,你就知道!')">
<input type="button" value="C盘" onClick="toDesktop('file://C:','C盘')">
2、ASP源码:
<%
Response.ContentType="APPLICATION/OCTET-STREAM"
Response.AddHeader "Content-Disposition","attachment;file信息窝网.url"
Response.Write("[InternetShortcut]")&Chr(13)
Response.Write("URL=http://www.wendabaike.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
%>
新建文本文档,复制上面的代码,保存为XXX.ASP(如zhuomian.ASP )
然后在适当的位置添加 <a href="/zhuomian.asp">保存到桌面</a>
3、PHP源码:
<?php
$Shortcut = "[InternetShortcut]
URL=http://www.66liu.com
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2";
Header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=66直播网.url;");
echo $Shortcut;
?>
或者
<?php
$Shortcut = "[InternetShortcut]
URL=http://www.08115.com
IconFile=http://www.08115.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;
?>
新建文本文档,复制上面的代码,保存为XXX.PHP(如zhuomian.PHP )
然后在适当的位置添加 <a href="/zhuomian.php">保存到桌面</a>
4、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>
/// 创建快捷方式
/// </summary>
/// <param>标题</param>
/// <param>URL地址</param>
private void CreateShortcut(string Title, string URL)
{
string strFavoriteFolder;
// “收藏夹”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
CreateShortcutFile(Title, URL, strFavoriteFolder);
// “ 桌面 ”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
CreateShortcutFile(Title, URL, strFavoriteFolder);
// “ 链接 ”中 创建 IE 快捷方式
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites) + "链接";
CreateShortcutFile(Title, URL, strFavoriteFolder);
//「开始」菜单中 创建 IE 快捷方式
CtrFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
CreateShortcutFile(Title, URL, strFavoriteFolder);
}
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param>标题</param>
/// <param>URL地址</param>
/// <param>特殊文件夹</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("岳池网", http://www.638300.com);
}
}
好了,就整理这/4种语言的网页快捷方式的方法,你现在可以按照上面的操作去测试效果了。