JS(javascript) 將網站加入收藏夾

來源:互聯網
上載者:User

標籤:

 
  • |
  • 瀏覽:688
  • |
  • 更新:2014-09-20 19:39
  • 1
  • 2
  • 3
分步閱讀

將網站網址加入收藏夾,方便下次訪問!

工具/原料
  • 網址;
  • 電腦。
方法/步驟
  1.  

    //建立加入收藏夾JS函數

    <script type="text/javascript">

    //定義加入收藏夾函數

    function join_favorite(siteUrl, siteName){  

     //捕獲加入收藏過程中的異常       

    try        {       

    //判斷瀏覽器是否支援document.all        

    if(document.all){                     

    //如果支援則用external方式加入收藏夾              

      window.external.addFavorite(siteUrl,siteName);                

     }else if(window.sidebar){                      

      //如果支援window.sidebar,則用下列方式加入收藏夾  

                      window.sidebar.addPanel(siteName, siteUrl,‘‘);         

           }          

         }  

     //處理異常       

    catch (e)        {          

     alert("加入收藏夾失敗,請使用Ctrl+D快速鍵進行添加操作!");   

        }

    }

    </script>

  2.  

    //調用加入收藏函數

     <a href="javascript:void(0);" title="wecandoitforev-baidujingyan"  onclick="join_favorite(window.location,document.title);">加入收藏</a>

  3.  

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

    <html>

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <title>加入收藏夾</title>

    <script type="text/javascript">

    //定義加入收藏夾函數

    function join_favorite(siteUrl, siteName){   

    //捕獲加入收藏過程中的異常       

    try        {      

     //判斷瀏覽器是否支援document.all         

    if(document.all){                      

    //如果支援則用external方式加入收藏夾                       

    window.external.addFavorite(siteUrl,siteName);                

     }else if(window.sidebar){                      

      //如果支援window.sidebar,則用下列方式加入收藏夾    

                    

    window.sidebar.addPanel(siteName, siteUrl,‘‘);            

    }                

    }   

    //處理異常      

     catch (e)        {          

     alert("加入收藏夾失敗,請使用Ctrl+D快速鍵進行添加操作!");     

      }

    }

    </script>

    </head>

    <body>

    <a href="javascript:void(0);" title="wecandoitforev-baidujingyan"  onclick="join_favorite(window.location,document.title);">加入收藏</a></body>

    </html>

  4.  

    //運行測試

  5.  

    加入收藏夾成功!!

    END
注意事項
  • 調用js加入函數,傳當前網址參數:window.location;
  • 調用js加入函數,傳當前網站名稱參數:document.title。

JS(javascript) 將網站加入收藏夾

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.