狼人干综合jq 设为首页 加入收藏加入收藏

完美兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面js代码
投稿:hebedich
字体:[ ] 类型:转载 时间:
这篇文章主要给大家分享了完美兼容IE,chrome,ff的设为首页、收藏本站及保存到桌面js代码,有需要的小伙伴参考下。
今天给大家分享一段设为首页、收藏本站及保存到桌面的js代码,非常实用。
&script& type="text/javascript"&
//设为首页
function SetHome(obj,url){
&&&&&&& 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) {
&&&&&&& window.external.addFavorite(url, title);
&&& catch (e) {
&&&&&&& try {
&&&&&&&&&&& window.sidebar.addPanel(title, url, "");
&&&&&&& catch (e) {
&&&&&&&&&&& alert("抱歉,您所使用的浏览器无法完成此操作。\n\n加入收藏失败,请使用Ctrl+D进行添加");
//保存到桌面
function toDesktop(sUrl,sName){
&&& var WshShell = new ActiveXObject("WScript.Shell");
&&& var oUrlLink =&&&&&&&&& WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop")&&&& + "\\" + sName + ".url");
&&& oUrlLink.TargetPath = sU
&&& oUrlLink.Save();
catch(e)& {&
&&&&&&&&& alert("当前IE安全级别不允许操作!");&
&a href="javascript:void(0);" onclick="SetHome(this,'');"&设为首页&/a&
&a href="javascript:void(0);" onclick="AddFavorite('我的网站',location.href)"&收藏本站&/a&
&a href="javascript:void(0);" onclick=" toDesktop(location.href,'我的网站')"&保存到桌面&/a&
这是从本人网站上扒下来滴,大家放心使用。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具posts - 245,&
comments - 49,&
trackbacks - 0
收藏本页的代码
&a href="javascript:" onClick="jscript:window.external.AddFavorite(document.location.href,document.title);"&收藏本页&/a&
收藏本站代码
&span style="CURSOR: hand" onClick="window.external.addFavorite('','网址')" title="网址"&收藏本站&/span&
设为首页代码
&a style="cursor:hand" onclick="this.style.behavior='url(#default#homepage)'; this.setHomePage('');"& 设为首页&u& Set as Home Page&/u&&/a&
阅读(...) 评论()嗨 朋友 欢迎你来到 龙果果的圈圈!要“知其然知其所以然”才能每天进步!
(@_@;)我是程序猿,我编程,我快乐,知识改变命运,技术成就梦想 & oh yeah!
随笔 - 197, 文章 - 1, 评论 - 31, 引用 - 0
&a href="javascript:;" id="setHomePage" class="toolsbar" onclick="setHomePage(this);"&设为主页&/a&
&a href="javascript:;" class="toolsbar" id="addFavorite" onclick="addFavorite(this);"&加入收藏&/a&
//设置首页
function setHomePage(obj) {
var aUrls = document.URL.split("/");
var vDomainName = "http://" + aUrls[2] + "/";
obj.style.behavior = "url(#default#homepage)";
obj.setHomePage(vDomainName);
} catch (e) {//other
if (window.netscape) {//Firefox
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-1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vDomainName);
if (window.netscape) alert("设置首页成功!");
return false; //阻止a标签继续执行
//加入收藏函数
function addFavorite(obj) {
var aUrls = document.URL.split("/");
var vDomainName = "http://" + aUrls[2] + "/";
var description = obj.
window.external.AddFavorite(vDomainName, description);
} catch (e) {//Firefox
window.sidebar.addPanel(description, vDomainName, "");
return false; //阻止a标签继续执行
function funBackTop() {
var elem = $('.backtop'), h = window.screen.height, time = null, srctop = 0;
this.init = function () {
elem.bind('click', function () {
$('#container').scrollTop(0);
time = setInterval(function () {
srctop = $('#container').scrollTop();
if (srctop & h) {
elem.show();
elem.hide();
设为首页 和 收藏本站js代码 兼容IE,chrome,ff
//设为首页
function SetHome(obj,url){
obj.style.behavior='url(#default#homepage)';
obj.setHomePage(url);
}catch(e){
if(window.netscape){
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("抱歉,此操作被浏览器拒绝!\n\n请在浏览器地址栏输入&about:config&并回车然后将[signed.applets.codebase_principal_support]设置为'true'");
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n您需要手动将【"+url+"】设置为首页。");
//收藏本站
function AddFavorite(title, url) {
window.external.addFavorite(url, title);
catch (e) {
window.sidebar.addPanel(title, url, "");
catch (e) {
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n加入收藏失败,请使用Ctrl+D进行添加");
&a href="javascript:void(0);" onclick="SetHome(this,document.domain);"&设为首页&/a&
&a href="javascript:void(0);" onclick="AddFavorite('我的网站',location.href)"&收藏本站&/a&
&copy 龙果果博客 &绞股蓝QQ群:网页设计教程与开发
提供各种常见网页效果
提供各种各样的设计教程
装扮QQ,让QQ变得更酷
设计参考,提高自升水平
学习服务器和操作系统
提供各种素材和工具
收藏学习资料
您现在的位置:&&>>&&>>&&>>&&>>&正文
设为首页代码和加入收藏代码(兼容各种浏览器)
破洛洛文章简介:史上最兼容的设为首页+加入收藏功能.
之前我测试过在ie下不报错的,可现在原因未知,页面在ie下报错了.本人正在解决.功能描述: 把页面设置为首页,加入收藏功能,支持ie,ff,chrome,safari,360安全,qq,遨游,搜狗浏览器,不兼容360急速浏览器的兼容模式下加入收藏功能注意:这里虽然说是兼容,但是有些浏览器的设置就是不支持用js来把页面设为首页,加入收藏夹,只能让用户手动去在浏览器或者按键去设置这些功能,这里说的兼容是指当浏览器有这个设置的时候js会有提示.至于这里说不兼容360急速,我这里有个demo,是360自己的网站,在360极速浏览器的兼容模式下都不支持&加入收藏&这个功能,它自己的浏览器上自己的页面都不支持这个功能.Code:
&!doctype html&&&html&&&head&&&title&把页面设置为首页,加入收藏功能,支持ie,ff,chrome,safari,360安全,qq,遨游,搜狗浏览器,不兼容360急速浏览器的加入收藏功能&/title&&
&/head&&&body&&&div&&&a href=&/&&首页&/a& | &&&&&&&&&&& &a onclick=&SetHome(window.location)& href=&javascript:void(0)&&设为首页&/a&&&&&&&&&&&&& | &a onclick=&AddFavorite(window.location,document.title)& href=&javascript:void(0)&&加入收藏&/a&&&&&&& &/div&&&&&&&& &script type=&text/javascript& language=&javascript&&&&&& //加入收藏&&&&&&&& function AddFavorite(sURL, sTitle) {&&&&&&&&&&&& sURL = encodeURI(sURL); &&&&&&& try{&& &&&&&&&&&&&& window.external.addFavorite(sURL, sTitle);&& &&&&&&&& }catch(e) {&& &&&&&&&&&&&& try{&& &&&&&&&&&&&&&&&& window.sidebar.addPanel(sTitle, sURL, &&);&& &&&&&&&&&&&& }catch (e) {&& &&&&&&&&&&&&&&&& alert(&加入收藏失败,请使用Ctrl+D进行添加,或手动在浏览器里进行设置.&);&&&&&&&&&&&& }&& &&&&&&&& }&&&& }&&&& //设为首页&&&& function SetHome(url){&&&&&&&& if (document.all) {&&&&&&&&&&&& document.body.style.behavior='url(#default#homepage)';&&&&&&&&&&&&&&& document.body.setHomePage(url);&&&&&&&& }else{&&&&&&&&&&&& alert(&您好,您的浏览器不支持自动设置页面为首页功能,请您手动在浏览器里设置该页面为首页!&);&&&&&&&& }&
&&& }&&/script&&&/body&&&/html&
转载请注明:破洛洛(谢谢合作)
上一篇文章: 下一篇文章:
网友评论:兼容IE和firefox的设置首页和加入收藏的JavaScript代码
如下分别是设为首页和加入收藏的代码效果:
&a href="#" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('')"&设为首页&/a&
&a href="javascript:window.external.AddFavorite('','PHP程序员的笔记')"&添加收藏&/a&
注意:以上代码仅适合IE内核的浏览器,现特将兼容IE和火狐浏览器的代码贴在下面:
//加入收藏
function AddFavorite(URL,Title){
URL=URL||window.location.
Title=Title||document.
window.external.addFavorite(URL,Title);
}catch(e){
window.sidebar.addPanel(Title,URL,"");
}catch(e){
alert("加入收藏失败,请使用Ctrl+D进行添加");
//设为首页
function setHomepage(URL){
URL=URL||window.location.
if(document.all){//IE类浏览器
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage(URL);
}else if(window.sidebar){//火狐类浏览器
if(window.netscape){
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}catch(e){
alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
var prefs=Components.classes['@mozilla.org/preferences-1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage',URL);
以上函数的在页面中的调用方式如下:
&a href ="javascript:void(0)" onclick ="setHomepage()"&设为首页&/a&
&a href="javascript:void(0)" onclick ="AddFavorite()"&加入收藏&/a&
&a href="javascript:void(0)" onclick ="AddFavorite('/','php程序员教程网')"&加入收藏&/a&您可能感兴趣的文章转载请注明出处:本文永久地址:文章来源:-わ千与千寻上一篇:下一篇:热门文章随机文章}

我要回帖

更多关于 jq 设为首页 加入收藏 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信