日期:2014-05-16  浏览次数:20349 次

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")%>