源于生活
标题:
php及js、asp实现将网址保存到桌面,设为桌面图标的代码
[打印本页]
作者:
kevin-ying
时间:
2015-5-15 01:24
标题:
php及js、asp实现将网址保存到桌面,设为桌面图标的代码
PHP代码教程
1、将下面的代码保存为文件,url.php。记得修改第二行及第四行内的url名称和网址。
<?php
$Shortcut = "[InternetShortcut]
URL=http://www.kevin-ying.com/
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
";
Header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=kevin-ying.url;");
echo $Shortcut;
?>
复制代码
2、将该文件上传至网站根目录。
3、在网站根目录上传Favicon.ico文件,有这个文件,保存的链接才会有图标显示。
4、在网站调用页面添加如下代码即可。
<a href='http://www.kevin-ying.com/url.php'>桌面图标</a>
附Asp代码 及Js代码
<%
Response.ContentType="APPLICATION/OCTET-STREAM"
Response.AddHeader "Content-Disposition","attachment;filename="&"kevin-ying.url"
Response.Write("[InternetShortcut]")&Chr(13)
Response.Write("URL=http://www.kevin-ying.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
%>
复制代码
js方法1
<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://www.kevin-ying.com/','kevin-ying')"
复制代码
js方法2
view sourceprint?
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=kevin-ying.url");
echo $Shortcut;
}
复制代码
欢迎光临 源于生活 (http://bbs.vingoo.info/)
Powered by Discuz! X3.1