紫衣仙女
尝试使用下面给出的代码在MozillaFirefox中获取客户端计算机名。netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' ); var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"]; var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);var compName = dnsSvc.myHostName;此外,同一段代码可以作为扩展,并可以从您的网页调用。请查找下面的示例代码。分机代码:var myExtension = { myListener: function(evt) {//netscape.security.PrivilegeManager.enablePrivilege( 'UniversalXPConnect' ); var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"]; var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);var compName = dnsSvc.myHostName;content.document.getElementById("compname").value = compName ; }}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(){ //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>