本篇文章主要是对js获取当前路径的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
Javascript 是一种由Netscape的LiveScript发展而来的原型化继承的基于对象的动态类型的区分大小写的客户端脚本语言,主要目的是为了解决服务器端语言,比如Perl,遗留的速度问题,为客户提供更流畅的浏览效果。
thisURL = document.URL;
thisHREF = document.location.href;
thisSLoc = self.location.href;
thisDLoc = document.location;
strwrite = " thisURL: [" + thisURL + "]
"
strwrite += " thisHREF: [" + thisHREF + "]
"
strwrite += " thisSLoc: [" + thisSLoc + "]
"
strwrite += " thisDLoc: [" + thisDLoc + "]
"
document.write( strwrite );
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
strwrite = " thisTLoc: [" + thisTLoc + "]
"
strwrite += " thisPLoc: [" + thisPLoc + "]
"
strwrite += " thisTHost: [" + thisTHost + "]
"
strwrite += " thisHost: [" + thisHost + "]
"
document.write( strwrite );
tmpHPage = thisHREF.split( "/" );
thisHPage = tmpHPage[ tmpHPage.length-1 ];
tmpUPage = thisURL.split( "/" );
thisUPage = tmpUPage[ tmpUPage.length-1 ];
strwrite = " thisHPage: [" + thisHPage + "]
"
strwrite += " thisUPage: [" + thisUPage + "]
"
document.write( strwrite );
var url="<%=request.getRequestURI()%>";
alert(url)
request.getRequestURI();
request.getRequestURL();
request.getQueryString();
request.getServletPath()
可以得到自己的网络地址:request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getRequestURI()
来源: