Skip to content

Instantly share code, notes, and snippets.

@reacher-lu
Created July 29, 2014 06:48
Show Gist options
  • Save reacher-lu/b6b074e4c85f91e446cb to your computer and use it in GitHub Desktop.
Save reacher-lu/b6b074e4c85f91e446cb to your computer and use it in GitHub Desktop.
document.referrer 获取来源网址
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