JS兼容多种浏览器的设为首页和加入收藏夹代码

模板网 2014-09-03

JS兼容多种浏览器的设为首页和加入收藏夹代码,设为首页和加入收藏夹分别对应两个函数setHomePage,addFavorite。

示例代码:

设为首页:<a href="javascript:;" onclick="setHomePage('http://www.120muban.com/');">设为首页</a> 

加入收藏夹:<a href="javascript:;" onclick="addFavorite('医疗模板库','http://www.120muban.com/')">加入收藏夹</a>

<title>JS兼容多种浏览器的设为首页和加入收藏夹代码</title>
<script>
function setHomePage(sURL) {
	if (document.all) {
		document.body.style.behavior = "url(#default#homepage)";
		document.body.setHomePage(sURL);
	}
	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", sURL);
	}
}

function addFavorite(sTitle, sUrl) {
	if (window.navigator.userAgent.indexOf("MSIE")>=1) {
		window.external.AddFavorite(sUrl, sTitle);
	}
	else if (window.navigator.userAgent.indexOf("Firefox")>=1) {
		window.sidebar.addPanel(sTitle, sUrl, "");
	}
	else {
		alert("加入收藏失败,请使用Ctrl+D进行添加!");
	}
}
</script>
<a href="javascript:;" onclick="setHomePage('http://www.120muban.com/');">设为首页</a> | 
<a href="javascript:;" onclick="addFavorite('医疗模板库','http://www.120muban.com/')">加入收藏夹</a>

相关文章

  1. Bcastr3.0详细使用教程

    Bcastr 3.0 beta flash 通用的图片浏览器 bcastr3.0 beta 是一款通用的图片浏览器 可以用于各种新闻系统或者blog系统 .可以读取xml设置播放列表,自定义xml地址 .可以将图片地址直接写网页中直接,不需要xml .自动适应图片大小 .循环播放,自定义自动播放时间

  2. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速

  3. html5输入框正则验证

    html5输入框正则验证,输入框禁止粘贴,禁止右键菜单。

  4. 使用新浪获取IP所在地接口做网站跳转

    使用新浪获取IP接口做网站跳转 title使用新浪获取IP接口做网站跳转/title !--引用新浪IP获取接口-- script type=text/javascript src=http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js/script !--引用新浪IP获取接口-- script type=text/javas

  5. HTML图片热区map area谷歌浏览器Google去除边框

    HTML图片热区map area去除边框默认的情况下 在Google浏览器中打开的时候周围会有蓝色的边框。 在area中加入以下代码可以去除边框: hidefocus=true onfocus=this.blur(); 完整代码如下: 复制代码 代码如下: img src=http://www.120muban.com/statics/images/l

随机推荐

  1. Bcastr3.0详细使用教程

    Bcastr 3.0 beta flash 通用的图片浏览器 bcastr3.0 beta 是一款通用的图片浏览器 可以用于各种新闻系统或者blog系统 .可以读取xml设置播放列表,自定义xml地址 .可以将图片地址直接写网页中直接,不需要xml .自动适应图片大小 .循环播放,自定义自动播放时间

  2. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速

  3. html5输入框正则验证

    html5输入框正则验证,输入框禁止粘贴,禁止右键菜单。

  4. 使用新浪获取IP所在地接口做网站跳转

    使用新浪获取IP接口做网站跳转 title使用新浪获取IP接口做网站跳转/title !--引用新浪IP获取接口-- script type=text/javascript src=http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js/script !--引用新浪IP获取接口-- script type=text/javas

  5. HTML图片热区map area谷歌浏览器Google去除边框

    HTML图片热区map area去除边框默认的情况下 在Google浏览器中打开的时候周围会有蓝色的边框。 在area中加入以下代码可以去除边框: hidefocus=true onfocus=this.blur(); 完整代码如下: 复制代码 代码如下: img src=http://www.120muban.com/statics/images/l