设为首页、加入收藏 兼容代码
2011-06-22 11:15
246 查看
一般写法:
<a href="javascript:window.external.AddFavorite(window.location.href,document.title)">加入收藏</a>
<a href="javascript:void()" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(location.href);">设为首页</a>
说明:这种写法是最常见的,兼容性不高
兼容写法:
<a onclick="AddFavorite(window.location,document.title)" href="javascript:void(0)">加入收藏</a>
<a onclick="SetHome(window.location)" href="javascript:void(0)">设为首页</a>
<script type="text/javascript" language="javascript">
//加入收藏
function AddFavorite(sURL, sTitle) {
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);
}
elseif (window.sidebar)
{
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',url);
}
}
</script>
说明:这种写法兼容性是比较高的
jquery超级交流群:36780982
阅读全文
类别:jquery/js 查看评论
<a href="javascript:window.external.AddFavorite(window.location.href,document.title)">加入收藏</a>
<a href="javascript:void()" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage(location.href);">设为首页</a>
说明:这种写法是最常见的,兼容性不高
兼容写法:
<a onclick="AddFavorite(window.location,document.title)" href="javascript:void(0)">加入收藏</a>
<a onclick="SetHome(window.location)" href="javascript:void(0)">设为首页</a>
<script type="text/javascript" language="javascript">
//加入收藏
function AddFavorite(sURL, sTitle) {
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);
}
elseif (window.sidebar)
{
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',url);
}
}
</script>
说明:这种写法兼容性是比较高的
jquery超级交流群:36780982
阅读全文
类别:jquery/js 查看评论
相关文章推荐
- 设为首页加入收藏兼容360/火狐/谷歌/IE/搜狗/猎狐/Safari/等主流浏览器的代码
- JS兼容所有浏览器的一段加入收藏代码,设置为首页
- javascript“设为首页”与“加入收藏”兼容多浏览器代码
- 兼容所有浏览器的加入收藏和设为首页代码
- 兼容各种浏览器的‘设为首页’和‘加入收藏’的js代码
- 设为首页加入收藏兼容360/火狐/谷歌/IE等主流浏览器的代码
- 加入收藏与设为首页代码(兼容各种浏览器)
- [代码收藏]设为首页和加入收藏的JavaScript代码(兼容多浏览器)
- 设为首页代码和加入收藏代码(兼容各种浏览器)
- javascript 设为首页与加入收藏兼容多浏览器代码
- 设为首页,加入收藏兼容360/火狐/谷歌/IE等主流浏览器的代码
- 设为首页代码和加入收藏代码-兼容各种浏览器
- 设为首页、加入收藏 兼容代码
- 设为首页|加入收藏(ie,f f兼容代码)
- 兼容IE,FF的设为首页与加入收藏代码
- 兼容IE和fireFox的设为首页、加入收藏JS代码
- 兼容IE、FF的设为首页,加入收藏代码
- 设为首页代码和加入收藏代码(兼容各种浏览器)
- 设为首页代码和加入收藏代码(兼容各种浏览器)