ต่อไปนี้มีหลายวิธีในการรับที่อยู่ URL โดย JS
การคัดลอกรหัสมีดังนี้:
thisurl = document.url;
Thishref = document.location.href;
thisloc = 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];
ต่อไปนี้เป็นวิธีการใช้ JS เพื่อรับที่อยู่ MAC ที่อยู่ IP และชื่อโฮสต์:
การคัดลอกรหัสมีดังนี้:
<html>
<head>
<title> </title>
<meta http-equiv = "content-type" content = "text/html; charset = gbk">
</head>
<body>
<Object classid = "ClSID: 76A64158-CB41-11D1-8B02-00600806D9B6" id = "locator" style = "แสดง: ไม่มี;
<Object classid = "ClSID: 75718C9A-F029-11D1-A1AC-00C04FB6C223" id = "foo" style = "แสดง: ไม่มี;
<form name = "myform">
<br/> ที่อยู่ MAC: <อินพุต type = "text" name = "macaddress">
<br/> ที่อยู่ IP: <อินพุต type = "text" name = "ipaddress">
<br/> ชื่อโฮสต์: <อินพุต type = "text" name = "hostname">
</form>
</body>
</html>
<ภาษาสคริปต์ = "JavaScript">
var smacaddr = "";
var sipaddr = "";
var sdnsname = "";
var service = locator.connectserver ();
Service.Security_.ImpersonationLevel = 3;
Service.instancesofasync (foo, 'win32_networkadapterconfiguration');
</script>
<script for = "foo" event = "onobjectready (objobject, objasyncContext)" language = "jscript">
if (objobject.ipenabled! = null && objobject.ipenabled! = "undefined" && objobject.ipenabled == true) {
if (objobject.ipenabled && objobject.ipaddress (0)! = null && objobject.ipaddress (0)! = "ไม่ได้กำหนด")
sipaddr = objobject.ipaddress (0);
if (objobject.macaddress! = null && objobject.macaddress! = "undefined")
smacaddr = objobject.macaddress;
if (objobject.dnshostname! = null && objobject.dnshostname! = "undefined")
sdnsname = objobject.dnshostname;
-
</script>
<script for = "foo" event = "oncompleted (hresult, perrorobject, pasyncContext)" language = "jscript">
myform.macaddress.value = smacaddr;
myform.ipaddress.value = sipaddr;
myform.hostname.value = sdnsname;
</script>