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

javascript获取当前页面的路径地址及目录
之前一直用ajax的方法异步请求从服务端获取,后来发现思路错了,用js获取多方便。
以下哪一个方法都可以的。
alert("window.location.href: " + window.location.href);
alert("window.location: " + window.location);
alert("location.href: " + location.href);
alert("parent.location.href: " + parent.location.href);
alert("top.location.href: " + top.location.href);
alert("document.location.href: " + document.location.href);
alert("document.URL: " + document.URL);
alert("last: "+ location.href.substring(0, location.href.lastIndexOf('/')));