JS javascript將網站加入收藏夾

JS javascript將網站加入收藏夾,第1張

JS(javascript) 將網站加入收藏夾。感興趣的小夥伴們快來了解一下吧。

    工具/材料

    電腦

    代碼

    • 01

      //創建加入收藏夾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>

      JS javascript將網站加入收藏夾,第2張
      • 02

        //調用加入收藏函數

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

        JS javascript將網站加入收藏夾,第3張
        • 03

          <!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>

          操作方法2

          • 01

            輸入完成之後,我們運行一下,看不看能不能成功,不成功的檢查一下自己的代碼是否有誤。


            生活常識_百科知識_各類知識大全»JS javascript將網站加入收藏夾

            0條評論

              發表評論

              提供最優質的資源集郃

              立即查看了解詳情