原生js編寫設為首頁相容ie、Firefox和Google

來源:互聯網
上載者:User

標籤:層級   name   Google   ext   void   ref   使用   無法   location   

 1 //設為首頁 2 //<a href="javascript:void(0);" onclick="SetHome(this,window.location)">設為首頁</a> 3 function SetHome(obj, url) { 4     try { 5         obj.style.behavior = ‘url(#default#homepage)‘; 6         obj.setHomePage(url); 7     } catch (e) { 8         if (window.netscape) { 9             try {10                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");11             } catch (e) {12                 alert("抱歉,此操作被瀏覽器拒絕!\n\n請在瀏覽器地址欄輸入“about:config”並斷行符號然後將[signed.applets.codebase_principal_support]設定為‘true‘");13             }14         } else {15             alert("抱歉,您所使用的瀏覽器無法完成此操作。\n\n您需要手動將【" + url + "】設定為首頁。");16         }17     }18 }19 //收藏本站20 //<a href="javascript:void(0);" onclick="AddFavorite(window.location,document.title)">加入收藏</a>21 function AddFavorite(title, url) {22     try {23         window.external.addFavorite(url, title);24     } catch (e) {25         try {26             window.sidebar.addPanel(title, url, "");27         } catch (e) {28             alert("抱歉,您所使用的瀏覽器無法完成此操作。\n\n加入收藏失敗,請使用Ctrl+D進行添加");29         }30     }31 }32 //儲存到案頭33 //<a href="javascript:void(0);" onclick="toDesktop(location.href,document.title)">儲存到案頭</a>34 function toDesktop(sUrl, sName) {35     try {36         var WshShell = new ActiveXObject("WScript.Shell");37         var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop") + "\\" + sName + ".url");38         oUrlLink.TargetPath = sUrl;39         oUrlLink.Save();40     } catch (e) {41         alert("當前IE安全層級不允許操作!");42     }43 }

 

原生js編寫設為首頁相容ie、Firefox和Google

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.