不去做怎么知道做不到,用心做好每一天做好每一件|

轻风细雨_林木木

园龄:6年3个月粉丝:4关注:1

IE,chrome,ff的设为首页、加入收藏及保存到桌面js实现

声明:该文章转自https://blog.csdn.net/qq_29362889/article/details/52033793,原作者更详细

js 部分代码

<script type="text/javascript">
//设为首页
function SetHome(obj,url){
try{
obj.style.behavior='url(#default#homepage)';
obj.setHomePage(url);
}catch(e){
if(window.netscape){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("抱歉,此操作被浏览器拒绝!\n\n请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
}
}else{
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n您需要手动将【"+url+"】设置为首页。");
}
}
}
//收藏本站
function AddFavorite(title, url) {
try {
window.external.addFavorite(url, title);
}
catch (e) {
try {
window.sidebar.addPanel(title, url, "");
}
catch (e) {
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
//保存到桌面
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>

HTTP 部分代码

<a href="javascript:void(0);" onclick="SetHome(this,'http://www.xyz.com');">设为首页</a>
<!-- “location.href” 表示当前url -->
<a href="javascript:void(0);" onclick="AddFavorite('我的网站',location.href)">收藏本站</a>
<a href="javascript:void(0);" onclick=" toDesktop(location.href,'我的网站')">保存到桌面</a>

本文作者:轻风细雨_林木木

本文链接:https://www.cnblogs.com/linzhifen5/p/16961409.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   轻风细雨_林木木  阅读(108)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 尚好的青春 孙燕姿
  2. 2 孙燕姿
  3. 3 克卜勒 孙燕姿
- 孙燕姿
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.