has collated a variety of page jump method referrer lost situation, which mentioned, in IE, using similar location.href = "a.html" in such a way to jump the page, in the target page Document.referrer value will be empty. This should be a bug for IE.
In most cases, this problem will not cause us any trouble, but sometimes we have to use JavaScript to jump, but also in the next page to collect Document.refer, then we have to think of other ways.
Form Get method
The first thought is to use form form, with JS to launch a GET request. The code resembles the following:
Copy Code code as follows:
function GoToPage (URL) {
if (Isie) {
IE browser
var frm = document.createelement ("form");
frm.action = URL;
Frm.method = "Get";
Document.body.appendChild (frm);
Frm.submit ();
} else {
Non IE
location.href = URL;
}
}
This method works as expected, and the document.referrer on the target page will normally point to the previous page.
A element analog click Method
A search on the internet found that Masaki's blog recorded another way to deal with the problem:
Copy Code code as follows:
Define for all browsers
function goto (URL) {
location.href = URL;
}
Re-Define for IE
if (Isie) {
function goto (URL) {
var referlink = document.createelement (' a ');
Referlink.href = URL;
Document.body.appendChild (Referlink);
Referlink.click ();
}
}
The principle is simple, first create a a element, specify its href attribute as the target link, and then use JS to trigger its click events. After testing, in the target page can also be normal access to document.referrer.
This method code is a little bit shorter and should be better than the one above using the form form.