Javascript 正常取来源网页的URL只要用:
- document.referrer
就可以了!
但,如果来源页是Javascript跳转过来的,上边的方法就拿不到了!所以用:
opener.location.href
所以,就有了下边的代码:
var ref = '';
if (document.referrer.length > 0) {
ref = document.referrer;
}
try { if (ref.length == 0 && opener.location.href.length > 0) {
ref = opener.location.href;
}
} catch (e) {}
其它相关的:
window.location.href :当前url
window.location.pathname :url中“/”以后的部分