JS获取当前页的URL的函数就是我们经常用来重定向的window.location.href。
<script>
var url=window.location.href;
var loc = url.substring(url.lastIndexOf('/')+1, url.length);
alert("url="+url+",loc="+loc);
</script>
如果当前页面是http://localhost:8080/test/cuihs1.htm,那么
url=http://localhost:8080/test/cuihs1.htm
loc=cuihs1.htm
另外,直接利用window.location.port拿端口,window.location.protocol拿协议,window.location.search还能拿问号之后的部分。
最后欢迎大家访问我的个人网站:1024s