兼容IE,Firefox,chrome等浏览器 : 设为首页和收藏的Javascript代码
2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062
2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods
推荐:兼容IE,Firefox,Chrome等浏览器 : 设为首页和加入收藏夹的Javascript代码
由于chrome,safari,opara 浏览器还未支持自动 “设为首页” & “加入收藏”. 所以我们只能try, catch一下, 给个错误提示! 也算完美了. 另外ie中, 很多人也碰
由于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('您的浏览器不支持自动自动设置首页, 请使用浏览器菜单手动设置!'); } }
推荐:设为首页加入收藏代码_兼容各浏览器ie系列Firefox
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.
相关阅读排行
- 1JavaScript 触发click事件 兼容FireFox,IE 和 Chrome
- 2谷歌chrome浏览器和火狐firefox浏览器自带http抓包工具和请求模拟插件
- 3五大浏览器js 判断IE、Firefox、Safari、Chrome、Opera
- 4JS日期选择器(兼容IE,Firefox,Opera等主流浏览器)
- 5google浏览器chrome无法导入IE收藏夹的问题