您现在的位置: 万盛学电脑网 >> 程序编程 >> 脚本专题 >> javascript >> 正文

js获取当前路径的示例代码

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 本篇文章主要是对js获取当前路径的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助

<script type="text/javascript">     thisURL = document.URL;  thisHREF = document.location.href;  thisSLoc = self.location.href;  thisDLoc = document.location;  strwrite = " thisURL: [" + thisURL + "]<br />"  strwrite += " thisHREF: [" + thisHREF + "]<br />"  strwrite += " thisSLoc: [" + thisSLoc + "]<br />"  strwrite += " thisDLoc: [" + thisDLoc + "]<br />"  document.write( strwrite );   thisTLoc = top.location.href;  thisPLoc = parent.document.location;  thisTHost = top.location.hostname;  thisHost = location.hostname;  strwrite = " thisTLoc: [" + thisTLoc + "]<br />"  strwrite += " thisPLoc: [" + thisPLoc + "]<br />"  strwrite += " thisTHost: [" + thisTHost + "]<br />"  strwrite += " thisHost: [" + thisHost + "]<br />"  document.write( strwrite );    tmpHPage = thisHREF.split( "/" );  thisHPage = tmpHPage[ tmpHPage.length-1 ];  tmpUPage = thisURL.split( "/" );  thisUPage = tmpUPage[ tmpUPage.length-1 ];  strwrite = " thisHPage: [" + thisHPage + "]<br />"  strwrite += " thisUPage: [" + thisUPage + "]<br />"  document.write( strwrite );  var url="<%=request.getRequestURI()%>"; alert(url) </script>    request.getRequestURI(); request.getRequestURL(); request.getQueryString();   request.getServletPath()   可以得到自己的网络地址:request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getRequestURI()