فيما يلي عدة طرق للحصول على عناوين URL بواسطة JS
نسخة الكود كما يلي:
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] ؛
فيما يلي طريقة استخدام 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 = "display: none ؛ الرؤية: مخفية"> </كائن>
<object classid = "clsid: 75718c9a-f029-11d1-a1ac-00c04fb6c223" id = "foo" style = "display: none ؛ الرؤية: مخفية"> </object>
<name form = "myForm">
<br/> عنوان MAC: <إدخال type = "text" name = "macaddress">
<br/> عنوان IP: <إدخال type = "text" name = "ipaddress">
<br/> اسم المضيف: <إدخال type = "text" name = "hostname">
</form>
</body>
</html>
<script language = "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)! = "undefined")
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>