The examples in this article describe the methods that JavaScript can take to determine and obtain trusted sites in the registry. Share to everyone for your reference. The specific analysis is as follows:
To determine the trusted site, first find the location of the trusted site in the registry in the registry, as follows:
(1) The location of the domain name as a trusted site in the registry:
Hkcu\\software\\microsoft\\windows\\currentversion\\internetsettings\\zonemap\\domains\\
(2) IP as the location of the trusted site in the registry:
Hkcu\\software\\microsoft\\windows\\currentversion\\internetsettings\\zonemap\\ranges
The specific test code is as follows:
INDEX.JSP:
JS Code:
* * To determine the trusted site (can be trusted site for IP address can also be domain name)/window.onload = function () {var btnobj = document.getElementById ("Testregiste
R "); Btnobj.onclick = function () {if (Navigator.userAgent.indexOf ("msie") = = 1) {alert ("Support IE browser only!")
");
Return
var hostname = Window.location.hostname;
var WshShell = new ActiveXObject ("Wscript.Shell"); The regular expression of IP var reg =/^ (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) (\. (
\D{1,2}|1\D\D|2[0-4]\D|25[0-5])) {3}$/; Determine if there is a trusted site based on the domain name if (hostname!= "localhost" &&!reg.test (hostname)) {var domainsflag = False,domainefl
AG = False,domainseflag = False,domainsseflag = true;
var hostnameprefix = "", Hostnamesuffix = "";
var indexOf = Hostname.indexof (".");
if (indexOf!=-1) {Hostnameprefix = hostname.substring (0, indexOf);
Hostnamesuffix = hostname.substring (indexof+1, hostname.length); try{WshShell.RegRead ("hkcu\\software\\microsoft\\windows\\currentversion\\internet settings\\zonemap\\domains\\ "+ hostname +" \\http ");
}catch (e) {Domaineflag = true; } if (Domaineflag) {try{WshShell.RegRead ("Hkcu\\software\\microsoft\\windows\\currentvers
Ion\\internet settings\\zonemap\\domains\\ "+ hostnamesuffix +" \ "+ Hostnameprefix +" \\http ");
}catch (e) {Domainsflag = true; }//Judge its legality if (Domaineflag && domainsflag) {try{Wshshell.regr EAD ("hkcu\\software\\microsoft\\windows\\currentversion\\internet settings\\zonemap\\domains\\" + HostnameSuffix +
"\" + Hostnameprefix + "\\*"); var tipinfo = "<div> you join a trusted site that is not a legitimate trusted site, please <span style= ' color:red; ' >http://</span> start!
</div> ";
alert (tipinfo);
Return }catch (e) {}}}else{try{WshShell.RegRead ("Hkcu\\software\\microsoft\\windows\\curren TVerSion\\internet settings\\zonemap\\domains\\ "+ hostname +" \\http ");
}catch (e) {Domainseflag = true; //Judge its legality if (Domainseflag) {try{WshShell.RegRead ("hkcu\\software\\microsoft\\w
Indows\\currentversion\\internet settings\\zonemap\\domains\\ "+ hostname +" \\* "); var tipinfo = "<div> you join a trusted site that is not a legitimate trusted site, please <span style= ' color:red; ' >http://</span> start!
</div> ";
alert (tipinfo);
Return }catch (e) {}}} if ((Domainsflag && domaineflag) | | domainseflag) {var tipinfo = "Domain The trusted site named "+ hostname +" does not exist!
";
alert (tipinfo);
alert (tipinfo);
Return
}else{//Get trusted site IP, number 2000 can not explain, mainly related to the problem of the registry var str = []; for (var i = 1;i < 2000;i++) {try{Str[i] = WshShell.RegRead ("hkcu\\software\\microsoft\\windows\\c Urrentversion\\internet Settings\\zonEmap\\ranges\\range "+ i +" \\:range ");
}catch (e) {}} var count = true;
for (var i = 1;i < str.length;i++) {if (str[i] = = undefined) {continue;
}else{if (str[i] = = hostname) {count = false;
Break '} ' if (count) {var tipinfo = ' IP is ' + hostname+ ' can be trusted site does not exist!
";
alert (tipinfo); return} alert ("There is a trustworthy site!")
");
}
}
The
wants this article to help you with your JavaScript programming.