js文件中怎么不能获取json内容
document.write("<scriptsrc=\"http://pv.sohu.com/cityjson?ie=utf-8\"></script>");docum...
document.write("<script src=\"http://pv.sohu.com/cityjson?ie=utf-8\"></script>");
document.write(returnCitySN["cip"]+','+returnCitySN["cname"]) ;
各位,有没什么办法在js文件中实现获取客户端ip物理地址的,在js文件中获取,而不是在html文件中 展开
document.write(returnCitySN["cip"]+','+returnCitySN["cname"]) ;
各位,有没什么办法在js文件中实现获取客户端ip物理地址的,在js文件中获取,而不是在html文件中 展开
1个回答
展开全部
在很多浏览器中,比如谷歌浏览器,用document.write引入新的JS文件,必须是本域下的,否则浏览器会认为是跨域包含攻击,会拦截下来,所以改成在HTML中引入就行了。
获取客户端详细地址的,我所知的只能是借助于IE的ActiveXObject来实现。代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JS获取客户端MAC地址</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<style type="text/css">
</style>
<script event="OnObjectReady(objObject,objAsyncContext)" for="foo">
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true) {
if(objObject.MACAddress != null && objObject.MACAddress != "undefined" && objObject.DNSServerSearchOrder!=null)
MACAddr = objObject.MACAddress;
if(objObject.IPEnabled && objObject.IPAddress(0) != null && objObject.IPAddress(0) != "undefined" && objObject.DNSServerSearchOrder!=null)
IPAddr = objObject.IPAddress(0);
if(objObject.DNSHostName != null && objObject.DNSHostName != "undefined")
sDNSName = objObject.DNSHostName;
}
</script>
<script type="text/javascript">
var MACAddr ;
var IPAddr ;
var DomainAddr;
var sDNSName;
function init() {
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = locator.ConnectServer();
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');
}
function getMac() {
document.getElementById('txtMac').value = unescape(MACAddr);
}
function getIp()
{
document.getElementById('txtIp').value = unescape(IPAddr);
}
</script>
</head>
<body onload="init()">
<object id="locator" classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" VIEWASTEXT></object>
<object id="foo" classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223"></object>
<input type="text" id="txtMac" />
<input type="button" id="btn" value="获取Mac地址" onclick="getMac();" />
<input type="text" id="txtIp" />
<input type="button" id="btn" value="获取ip地址" onclick="getIp();" />
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询