다음은 JS가 URL 주소를 얻는 몇 가지 방법입니다.
코드 사본은 다음과 같습니다.
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 ( "/");
이 upage = tmpupage [tmpupage.length-1];
다음은 JS를 사용하여 Mac 주소, IP 주소 및 호스트 이름을 얻는 방법입니다.
코드 사본은 다음과 같습니다.
<html>
<헤드>
<제목> </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>
<Object ClassId = "ClsID : 75718C9A-F029-11D1-A1AC-00C04FB6C223"id = "foo"style = "display : none; 가시성 : 숨겨진"> </object>
<form name = "myform">
<br/> Mac 주소 : <입력 유형 = "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.instancesofasync (foo, 'win32_networkadapterconfiguration');
</스크립트>
<script for = "foo"event = "onobjectready (objobject, objasynccontext)"언어 = "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 for = "foo"event = "oncompleted (hresult, perrorobject, pasynccontext)"언어 = "jscript">
myform.macaddress.value = smacaddr;
myform.ipaddress.value = sipaddr;
myform.hostname.value = sdnsname;
</스크립트>