Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Redirect based on Referrer?

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

like image 757
Petey B Avatar asked Jul 08 '09 15:07

Petey B


1 Answers

if (document.referrer != "") {
   var referringURL = document.referrer;
   var local = referringURL.substring(referringURL.indexOf("?"), referringURL.length);
   location.href = "http://page.com/login" + local; 
}
like image 162
Josh Avatar answered Sep 26 '22 13:09

Josh