Heim > Artikel > Web-Frontend > js获取当前路径的简单示例代码_javascript技巧
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="";
alert(url)
request.getRequestURI();
request.getRequestURL();
request.getQueryString();
request.getServletPath()
可以得到自己的网络地址:request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getRequestURI()