读书人

JS字符串连接与自动获取服务器IP有关问

发布时间: 2012-03-27 13:44:24 作者: rapoo

JS字符串连接与自动获取服务器IP问题
在**.js文件中
var __cc_sys_url ="http://192.168.0.42:8081/count/"
//var __cc_sys_url ="http://"+window.location.host+":"+window.location.port+"/count/"
及***.asp文件中
<script language="JavaScript"
src="http://192.168.0.42:8081/count/**.js">
</script>

我想改成自动获取当前服务器IP及端口号
所以改成了如下:
在**.js文件中
var __cc_sys_url ="http://"+window.location.host+":"+window.location.port+"/count/"
及***.asp文件中
<script language="JavaScript"
src="http://"+window.location.host+":"+window.location.port+"/count/**.js">
</script>

这样改不行,莫非把window.location改成document.location ,大家帮帮忙吧,谢谢了

[解决办法]
获取服务器IP: <%=Request.ServerVariables("LOCAL_ADDR")%>

端口号:<%=Request.ServerVariables("SERVER_PORT")%>
[解决办法]

HTML code
JS文件<script type="text/javascript">var __cc_sys_url = "http://"+window.location.host + ":" + window.location.port+"/count/" ;</script>asp文件<%url = "http://" + Request.ServerVariables("HTTP_HOST") + ":" + Request.ServerVariables("SERVER_PORT") + "/count/**.js"%><script type="text/javascript" src="<%=url%>"></script>
[解决办法]
探讨
获取服务器IP: <%=Request.ServerVariables("LOCAL_ADDR")%>

端口号: <%=Request.ServerVariables("SERVER_PORT")%>

读书人网 >JavaScript

热点推荐