Under IE implement location.href through a to get the value of the referer

  • 2020-03-30 03:51:04
  • OfStack

Recently, the company's website needs to count the pages from which users enter the registration page. At first, it is simply fetched on the server side by $_SERVER['HTTP_REFERER'] (PHP). However, it was found that many registered users did not have a referer value. Later, I checked to see that if I jumped in the window.location.href mode under IE, the referer value was null. And on the label < A> < / a> The inside skip referer will not be empty. Therefore, this IE problem can be solved by following the code:

function gotoUrl(url){ 
var gotoLink = document.createElement('a'); 

gotoLink .href = url; 


gotoLink .click(); 

else window.location.href = url; 

The idea is to create a tag. A> , then set the url to jump to, and finally trigger the click event.

Related articles: