為了讓網站能載入系統控制項,並在彈出視窗時不再跳出提示,可以透過 WScript.Shell 直接寫入機碼來完成。以下先說明各機碼路徑的含義。
可信站點的機碼位置
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range[*]
ActiveX 控件的機碼位置
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\[0-4]\[*]
含義說明
ActiveX 設定值:3 為禁用,0 為啟用,1 為提示。
機碼中 [0-4] 的含義
機碼中 [*] 的含義
彈出視窗封鎖的機碼位置
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\New Windows\PopupMgr
具體腳本
<SCRIPT LANGUAGE="JavaScript">
<!--
var WshShell = new ActiveXObject("WScript.Shell");
// 加入可信站點或 IP
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\", "");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\http", "2", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range100\\:Range", "www.jb51.net");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\", "");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\http", "2", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range101\\:Range", "www.example.com");
// 修改 IE ActiveX 安全設定
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1001", "0", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1004", "0", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1200", "0", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1201", "0", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\1405", "0", "REG_DWORD");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3\\2201", "0", "REG_DWORD");
// 關閉彈出視窗封鎖
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Internet Explorer\\New Windows\\PopupMgr", "no");
alert("可信站點設定、ActiveX 控件安全設定、彈出視窗設定成功");
//-->
</SCRIPT>
如果只想手動把某個網域加進可信站點,步驟如下:
1.開啟 regedit,依序展開 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains
2.新增一個機碼:「jb51.net」
3.在 jb51.net 下再新增:「www」
4.在 www 下新增一個字串值:「*」(代表任何協定,也可改成 http、ftp 等單一協定)
5.雙擊該字串值,基數選「十六進位制」,數值資料填「2」(代表可信站點)
6.關閉機碼編輯器
<SCRIPT LANGUAGE="JavaScript">
<!--
var WshShell = new ActiveXObject("WScript.Shell");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\jb51.net", "");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\jb51.net\\www", "");
WshShell.RegWrite("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains\\jb51.net\\www\\http", "2", "REG_DWORD");
alert("成功將 jb51.net 寫入到可信站點");
//-->
</SCRIPT>
最後必須誠實提醒:以上做法僅適用於早期的 IE 內網環境。現代瀏覽器早已移除 ActiveX 與這類機碼控制項,而讓網頁安靜地降低瀏覽器安全等級本身就是高風險行為——它同時也為惡意網站開了後門。新專案請改用標準 Web API(File API、Notification、Service Worker 等),或透過企業的群組原則統一派發設定,不要靠頁面腳本改機碼。