加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

加入收藏 设为首页 代码:兼容IE和FireFox

(2007-11-24 22:17:54)
标签:

it/科技

加入收藏

兼容ie

firefox

 

<script type="text/javascript">
function addfavorite()
{
if (document.all)
{
window.external.addFavorite('http://www.aspxuexi.com‘,"asp"学习网");
}
else if (window.sidebar)
{
window.sidebar.addPanel("asp学习网", "http://www.aspxuexi.com","");
}
}
</script>
<a href="#" onclick="addfavorite()">加入收藏</a>

 


 

<script type="text/javascript">
<!--
function myAddPanel(title,url,desc)
{
if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))

//Gecko
{
window.sidebar.addPanel(title,url,desc);
}
else

//IE
{
window.external.AddFavorite(url,title);
}
}
//-->
</script>
<span onClick="myAddPanel('asp学习网','http://www.aspxuexi.com','aspxuexi.com)">加入收藏</span>


另外在firefox下还有一种很方便的方法添加到书签,就是在a标签里使用rel,标志rel=”sidebar”

<a href='http://www.aspxuexi.com' title="aspxuexi" rel="sidebar">bookmark</a>

因此可以这样:

function showfr()
{
if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
//Gecko for firefox
{
document.writeln("<a href=\"http:\/\/www.aspxuexi.com\" title=\"asp学习网\" rel=\"sidebar\">Bookmark[firefox]<\/a>")
}
else
//IE
{
document.writeln("<a href=\"#\" onclick=\"window.external.addFavorite(\'http:\/\/www.aspxuexi.com\',\'asp学习网\');\">收藏此站点<\/a>");
}

}

然后调用这个showfr;

顺便说一下,是兼顾而不是兼容。

 

加入收藏

另外一种方法:

function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败,请使用Ctrl+D进行添加");
        }
    }
}
使用:
<a onclick="AddFavorite(window.location,document.title)">加入收藏</a>

设为主页

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);
                 }
        }
}
使用:
<a onclick="SetHome(this,window.location)">设为首页</a

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有