Berikut ini adalah beberapa cara untuk mendapatkan alamat URL oleh JS
Salinan kode adalah sebagai berikut:
thisUrl = document.url;
thishref = document.location.href;
thissloc = self.location.href;
thisdloc = document.location;
Thistloc = top.location.href;
thisploc = parent.document.location;
thisthost = top.location.hostname;
thishost = location.hostname;
tmphpage = thishref.split ("/");
thishpage = tmphpage [tmphpage.length-1];
tmpupage = thisUrl.split ("/");
thisUpage = tmpupage [tmpupage.length-1];
Berikut ini adalah metode untuk menggunakan JS untuk mendapatkan alamat MAC, alamat IP dan nama host:
Salinan kode adalah sebagai berikut:
<Html>
<head>
<title> </title>
<meta http-equiv = "konten tipe" content = "text/html; charset = gbk">
</head>
<body>
<objek classid = "clsid: 76a64158-cb41-11d1-8b02-00600806d9b6" id = "locator" style = "display: tidak ada; visibilitas: tersembunyi"> </ object>
<object classId = "clsid: 75718c9a-f029-11d1-a1ac-00c04fb6c223" id = "foo" style = "display: none; visibilitas: tersembunyi"> </object>
<Form name = "myForm">
<br/> Alamat Mac: <Input type = "Text" Name = "MacAddress">
<br/> Alamat IP: <input type = "Text" name = "ipaddress">
<br/> Nama Host: <Input Type = "Text" Name = "HostName">
</form>
</body>
</html>
<bahasa skrip = "javascript">
var smacaddr = "";
var sipaddr = "";
var sdnsname = "";
var service = locator.connectServer ();
service.security_.impersonationlevel = 3;
service.instancesofasync (foo, 'win32_networkAdapterConfiguration');
</script>
<skrip untuk = "foo" event = "onobjectready (objObject, objasynccontext)" language = "jscript">
if (objObject.ipeNabled! = null && objObject.ipeNabled! = "tidak terdefinisi" && objObject.ipeNabled == true) {
if (objObject.ipeNabled && objObject.ipaddress (0)! = null && objObject.ipaddress (0)! = "tidak terdefinisi")
sipaddr = objObject.ipaddress (0);
if (objObject.macaddress! = null && objObject.macaddress! = "tidak terdefinisi")
smacaddr = objObject.macaddress;
if (objObject.dnshostname! = null && objObject.dnshostname! = "tidak terdefinisi")
sdnsname = objObject.dnshostname;
}
</script>
<skrip untuk = "foo" event = "onCompleted (hResult, perrorObject, pasynccontext)" language = "jscript">
myform.macaddress.value = smacaddr;
myform.ipaddress.value = sipaddr;
myForm.hostname.value = sdnsname;
</script>