JavaScript Redirect based on Referrer?

 ̄綄美尐妖づ 提交于 2020-01-12 03:23:06

问题


Is there anyway to grab the referring URL using javascript, lets say the reffering url is http://page.com/home?local=fr, then redirect a user to a new page with the same local as the reffering page (http://page.com/login?local=referring local)?

Pseudo code would be something like this:

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

Thanks, -Pete


回答1:


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


来源:https://stackoverflow.com/questions/1098877/javascript-redirect-based-on-referrer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!