Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /www/web/webqin_net/public_html/inc/mysql_class.php on line 8
jquery设为首页、加入收藏代码(兼容360/火狐/谷歌/IE浏览器)-上海网站建设公司_网站设计_网站制作_软件开发公司-上海秦王网络公司|专业的上海网站建设公司

jquery设为首页、加入收藏代码(兼容360/火狐/谷歌/IE浏览器)

时间:2014-08-22 来源:上海网站建设公司(秦王网络) 点击量:10435

jquery设为首页与加入收藏代码,可以兼容360、火狐、谷歌、IE等主流浏览器,以下由上海秦王网络公司整理,有需要的朋友可以参考下。

设为首页及加入收藏的js代码,如下:

<script type="text/javascript"> 
// 设置为主页 
function SetHome(obj,vrl){ 
try{ 
obj.style.behavior= url(#default#homepage) ;obj.setHomePage(vrl); 

catch(e){ 
if(window.netscape) { 
try { 
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 

catch (e) { 
alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为 true ,双击即可。"); 

var prefs = Components.classes[ @mozilla.org/preferences-service;1 ].getService(Components.interfaces.nsIPrefBranch); 
prefs.setCharPref( browser.startup.homepage ,vrl); 
}else{ 
alert("您的浏览器不支持,请按照下面步骤操作:\n1.打开浏览器设置。\n2.点击设置网页。\n3.输入:"+vrl+"点击确定。"); 



// 加入收藏 兼容360和IE6 
function shoucang(sTitle,sURL) 

try 

window.external.addFavorite(sURL, sTitle); 

catch (e) 

try 

window.sidebar.addPanel(sTitle, sURL, ""); 

catch (e) 

alert("加入收藏失败,请使用Ctrl+D进行添加"); 


}
</script>


调用代码:
<a href="javascript:void(0)" onclick="SetHome(this, http://www.cn7080.com )">设为首页</a>
<a href="javascript:void(0)" onclick="shoucang(document.title, http://www.cn7080.com )">加入收藏</a>



以下是各种样式的加入收藏和设为主页代码。
不过,此代码只兼容IE浏览器。

1、加入收藏
<a href="javascript:window.external.AddFavorite(‘http://www.jbxue.com‘,‘脚本学堂‘)">加入收藏</a> 
如果要实现鼠标划过时即提示是否加入收藏,将代码修改为:
<a onmouseover="window.external.addFavorite(‘http://www.jbxue.com‘,‘脚本学堂‘)" target=_self href= >加入收藏</a>

2、设为首页
<a onclick="this.style.behavior= url(#default#homepage) ;this.setHomePage( http://www.cn7080.com/ );"></a>

离开时自动提示设为首页
<body onunload="BASEBody.style.behavior= url(#default#homepage) ;if(!(BASEBody.isHomePage( http://www.cn7080.com/ )))BASEBody.setHomePage( www.cn7080.com/ );"> 


1)、打开页面时自动弹出窗口询问是否设为首页
将以下代码放在<head></head>之间: 
<script language="javascript"> 
function myhomepage(){ 
this.homepage.style.behavior= url(#default#homepage) ;this.homepage.sethomepage( http://www.cn7080.com ); 

</script> 
<a href="http://www.cn7080.com/" name="homepage" onclick="myhomepage();"></a> 
再将下面代码加入<body>内:
onload="myhomepage();" 
即:<body onload="myhomepage();">

2)、鼠标指向时提示设为首页 
将下列代码插入<body>区中:
<A href="http://www.cn7080.com/" onmouseover ="this.style.behavior= url(#default#homepage) ;this.setHomePage(‘http://www.cn7080.com/ );" target="_blank">设为首页</A>

3)、关闭当前窗口的功能 
先输入用来标示的文字“关闭窗口",用鼠标拖动选中它,在“Link"输入框中键入“/",同时切入源代码窗口,在链接代码中键入该事件
onclick="javascript:window.close(); return false;" 
完整代码:<a href="/" onclick="javascript:window.close(); return false;">关闭窗口</a>