標籤:層級 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