博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
兼容IE,Firefox,chrome等浏览器 : 设为首页和收藏的Javascript代码
阅读量:4356 次
发布时间:2019-06-07

本文共 1507 字,大约阅读时间需要 5 分钟。

由于chrome,safari,opara 浏览器还未支持自动 "设为首页" & "加入收藏".  所以我们只能try, catch一下, 给个错误提示!  也算完美了.

 

另外ie中, 很多人也碰到过 它window.external.addFavorite.  时会报错的问题.  所以俺也只好抛出提示信息了.

 

加入收藏: 

/** author : 2010-12-27 11:33:02 teresa* discription: add favorite*/function addFavorite(){    if (document.all){        try{            window.external.addFavorite(window.location.href,document.title);        }catch(e){            alert( "加入收藏失败,请使用Ctrl+D进行添加" );        }            }else if (window.sidebar){        window.sidebar.addPanel(document.title, window.location.href, "");     }else{        alert( "加入收藏失败,请使用Ctrl+D进行添加" );    }}

设为首页:

/** author : 2010-12-27 11:33:02 teresa* discription: set homepage*/function setHomepage(){    if (document.all){        document.body.style.behavior='url(#default#homepage)';          document.body.setHomePage(window.location.href);    }else if (window.sidebar){        if(window.netscape){            try{                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");            }catch (e){                alert( "该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );            }        }        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);        prefs.setCharPref('browser.startup.homepage',window.location.href);    }else{        alert('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!');    }}

 

 

转载于:https://www.cnblogs.com/firesnow/archive/2012/07/25/2607934.html

你可能感兴趣的文章
数学图形之鞍面
查看>>
seajs +gruntjs 合作开发
查看>>
电子书下载:Professional Web Design: Techniques and Templates, 4th Edition
查看>>
[5]windows内核情景分析---进程线程
查看>>
Identity Server 4 原理和实战(完结)_单点登录实例(添加Flask客户端,Express.js的API)...
查看>>
Fluuter常遇到的问题
查看>>
Poj 2662,2909 Goldbach's Conjecture (素数判定)
查看>>
Longest Palindromic Substring
查看>>
ps,mp,html
查看>>
C/C++字符串使用整理
查看>>
windows下的txt文件传到Linux下中文乱码问题
查看>>
【iCore3应用开发平台】发布 iCore3 应用开发平台出厂代码rev0.0.1
查看>>
Leetcode Remove Nth Node From End of List
查看>>
计算机基础小结
查看>>
XP HOME版 安装IIS
查看>>
css发展史与其他知识
查看>>
HTML5移动Web开发(七)——通过界面图标启动Web应用
查看>>
单人纸牌_NOI导刊2011提高(04) [题解]
查看>>
phpcms v9 删除更新提醒信息
查看>>
resource
查看>>