'加入收藏' 功能

第一種寫法:例子

<a href="javascript:void(0);" target="_self" onclick="javascript:try{ window.external.AddFavorite('http://www.butao.com','步淘'); } catch(e){ (window.sidebar)?window.sidebar.addPanel('360安全網址','http://hao.360.cn/',''):alert('請使用按鍵 Ctrl+d,收藏360安全網址'); }">加入收藏</a>

第二種寫法:例子

<a href="#" onclick="addfavorite()">加入收藏!</a>

<script>
    function addfavorite(){

       if (document.all){
          window.external.addFavorite('http://www.baidu.com','收藏夾');

       } else if (window.sidebar){
          window.sidebar.addPanel('百度一下', 'http://www.baidu.com', "");

       } else {  
         alert( "請使用 Ctrl+D 進行添加" );
       }

    }
</script>

第三種寫法:例子

<a href="javascript:;" onclick="AddFavorite('http://www.butao.com','butao')">把www.butao.com加入收藏</a>

<script>
    function AddFavorite(sURL, sTitle){
       try{
           window.external.addFavorite(sURL, sTitle);
       } catch (e){
           try{
               window.sidebar.addPanel(sTitle, sURL, "");
           } catch (e){
               alert("加入收藏失敗,請使用Ctrl+D進行添加");
           }
       }
    }
</script>

第四種寫法:例子

<a href="javascript:;" onclick="javascript:addfavor(' http://www.butao.com','butao');">加入收藏</a>

<script language="javascript">
    function addfavor(url,title) {
        if(confirm("網站名稱:"+title+"n網址:"+url+"n確定添加收藏?")){
            var ua = navigator.userAgent.toLowerCase();
            if(ua.indexOf("msie 8")>-1){
                external.AddToFavoritesBar(url,title,'butao');  //IE8
            }else{
                try {
                    window.external.addFavorite(url, title);
                } catch(e) {
                    try {
                        window.sidebar.addPanel(title, url, "");  //firefox
                    } catch(e) {
                        alert("加入收藏失敗,請使用Ctrl+D進行添加");
                    }
                }
            }
        }
        return false;
    }
</script>

第五種寫法:例子

<a href="javascript:void();" οnclick="addfavorite()">將本頁加入收藏</a>

<script language="javascript">
var isIE =(document.all&&document.getElementByIdx_x_x_x_x_xx_x&&!window.opera)?true:false;
var isMozilla=(!document.all&&document.getElementByIdx_x_x_x_x_xx_x&&!window.opera)?true:false;

var weburl=window.location.href;
var webname=document.title;

function addfavorite(){
    if(isMozilla){
        if (document.all){
            window.external.addFavorite(weburl,webname);
        }else if(window.sidebar){
            window.sidebar.addPanel(webname,weburl,"");
        }
    } if(isIE){
        window.external.AddFavorite(weburl, webname);
    }
}
</script>

第六種寫法:使用圖片實現加入收藏的效果:

<a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com');" href="javascript:;" title="設爲首頁"><img src="Images/about_2.gif" border="0" width="84" height="19" title="設爲首頁" /></a>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章