-
-
Save reacher-lu/b6b074e4c85f91e446cb to your computer and use it in GitHub Desktop.
document.referrer 获取来源网址
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment