如何从浏览器中读取客户端的计算机/计算机名称?

如何从浏览器中读取客户端的计算机/计算机名称?
是否可以使用JavaScript和/或ASP.NET?

哆啦的时光机
浏览 1405回答 3
3回答

慕容3067478

浏览器、操作系统、屏幕颜色、屏幕分辨率、Flash版本和Java支持都应该可以从JavaScript(或者更多)中检测到。但是,计算机名是不可能的。编辑:至少不可能跨越所有浏览器。

紫衣仙女

尝试使用下面给出的代码在MozillaFirefox中获取客户端计算机名。netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );&nbsp;var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"];&nbsp;var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);var compName = dnsSvc.myHostName;此外,同一段代码可以作为扩展,并可以从您的网页调用。请查找下面的示例代码。分机代码:var myExtension = {&nbsp; myListener: function(evt) {//netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' );&nbsp;var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"];&nbsp;var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);var compName = dnsSvc.myHostName;content.document.getElementById("compname").value = compName ;&nbsp; &nbsp;&nbsp;&nbsp; }}document.addEventListener("MyExtensionEvent", function(e) { myExtension.myListener(e); }, false, true); //this event will raised from the webpage网页代码:<html><body onload = "load()"><script>function showcomp(){alert("your computer name is " + document.getElementById("compname").value);}function load(){&nbsp;//var element = document.createElement("MyExtensionDataElement");//element.setAttribute("attribute1", "foobar");//element.setAttribute("attribute2", "hello world");//document.documentElement.appendChild(element);var evt = document.createEvent("Events");evt.initEvent("MyExtensionEvent", true, false);//element.dispatchEvent(evt);document.getElementById("compname").dispatchEvent(evt); //this raises the MyExtensionEvent event , which assigns the client computer name to the hidden variable.}</script><form name="login_form" id="login_form"><input type = "text" name = "txtname" id = "txtnamee" tabindex = "1"/><input type="hidden" name="compname" value="" id = "compname" /><input type = "button" onclick = "showcomp()" tabindex = "2"/></form></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP