+ -
当前位置:首页 → 问答吧 → 求把网页加入收藏夹的通用代码

求把网页加入收藏夹的通用代码

时间:2010-09-23

来源:互联网

我在网上找的这个代码
HTML code
<a style="font-size:18px; font-weight:bold; color:#999;" href="#" onClick="window.external.addFavorite('http://jingdn.com','jingdn.com');" 
title="jingdn">Add me to your favorite list!</a>

在ie下可以调出来网页收藏对话框,但是firefox不好使,别的浏览器还没有测试,请达人告知一个通用的写法,就是在各个浏览器中都能用的代码,谢谢!

作者: anuosix   发布时间: 2010-09-23

JScript code

function AddFavorite(strUrl,strTitle){
        if (document.all){
             window.external.addFavorite(strUrl,strTitle);
         }else if (window.sidebar) {
             window.sidebar.addPanel(strTitle,strUrl,'');
         }
}




IE和FF是没问题的

作者: xiaofanku   发布时间: 2010-09-23

http://hi.baidu.com/jaywclove/blog/item/855e9464d1cf08fdf6365425.html

作者: q107770540   发布时间: 2010-09-23

http://www.w3help.org/zh-cn/causes/BX2033

作者: mochimo   发布时间: 2010-09-23

JScript code

<script type="text/javascript">
function addFavorite(url,title){
    if(window.sidebar||window.opera)return true;
    try{
        window.external.AddFavorite(url,title);
    }
    catch(e){
        alert("请按下 Ctrl + D 键将本站加入收藏。");
    }
    return false;
}
</script>
<a href="http://www.google.com" title="google" rel="sidebar" onclick="return addFavorite('http://www.google.com','Google');">加入收藏</a>

作者: mochimo   发布时间: 2010-09-23