基于Referrer的JavaScript重定向?

时间:2009-07-08 15:36:26

标签: javascript redirect referrer

无论如何使用javascript获取引用网址,让我们说相关网址为http://page.com/home?local=fr,然后将用户重定向到与该网页相同的本地网页(http://page.com/login?local= 引用本地)?

伪代码会是这样的:

var referringURL = document.referrer;
var local = referringURL.substring(referringURL.indexOf("?"), referringURL.length())
var newURL = "http://page.com/login" +local;
Send user to newURL

谢谢,-Pete

1 个答案:

答案 0 :(得分:17)

if (document.referrer != "") {
   var referringURL = document.referrer;
   var local = referringURL.substring(referringURL.indexOf("?"), referringURL.length);
   location.href = "http://page.com/login" + local; 
}