0

This code works in Google Chrome but not in IE and Firefox. The site "somesite.org" send me 302 (redirect). I want to redirect when it comes from a specific site (somesite.org) to a specific file in my site.

Code:

var url = document.referrer; 

if (url.includes("somesite.org")) { 
    window.location.href = "http://forthisfile.com/this.html"
}
Jerrybibo
  • 1,315
  • 1
  • 21
  • 27
BRS
  • 3
  • 2
  • See: IE did not set document.referrer StackOverFlow: [Equivalent document.referrer others](https://stackoverflow.com/questions/13681156/ie-did-not-set-document-referrer) – grecio beline Jul 17 '18 at 17:32

2 Answers2

0

This should work

var url = document.referrer;

    if(url.indexOf("somesite.org") > -1 ){

      window.location = "http://forthisfile.com/this.html" ;
    }
Anshul Bansal
  • 1,833
  • 1
  • 13
  • 12
0

IE does not support any form of includes, see MDN reference page.

that said, the alternative is to check the hash:

if(window.location.hash.indexOf("?") >= 0) {
    ...
}

so in your case:

  if(window.location.hash.indexOf("somesite.org") > -1 ){

      window.location = "http://forthisfile.com/this.html" ;
    }
Barr J
  • 10,636
  • 1
  • 28
  • 46
  • Works fine in Chrome, same as before in IE and Firefox. I saw that the referer in IE and Firefox comes in blank, different from chrome. – BRS Jul 18 '18 at 13:01