javascript获取来源的URL代码
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 window.location.pathname
var num = Math.round(Math.random()*10000); window.location.href = (window.location.pathname)+'?'+num+';
var num = Math.round(Math.random()*10000); window.location.href = (window.location.pathname)+'?'+num+';