Ниже приведены несколько способов получить адреса URL -адреса JS
Кода -копия выглядит следующим образом:
thisurl = document.url;
thishref = document.location.href;
thissloc = self.location.href;
thisdloc = document.location;
thistloc = top.location.href;
thisploc = parent.document.location;
thishost = 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>
<голова>
<title> </title>
<meta http-equiv = "content-type" content = "text/html; charset = gbk">
</head>
<тело>
<Object classid = "clsid: 76a64158-cb41-11d1-8b02-00600806d9b6" id = "locator" style = "display: none; Видимость: Hidden"> </Object>
<Object classid = "clsid: 75718c9a-f029-11d1-a1ac-00c04fb6c223" id = "foo" style = "display: none; видимость: hidden"> </object>
<form name = "myform">
<br/> mac -адрес: <input type = "text" name = "macaddress">
<br/> IP -адрес: <input type = "text" name = "iPaddress">
<br/> Имя хоста: <input 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.InstanceOfAsync (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! = "Не определено")
smacaddr = objobject.macaddress;
if (objobject.dnshostname! = null && objobject.dnshostname! = "Не определено")
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>