JS complete code:
Copy Code code as follows:
<script language= "JavaScript" >
var refer=document.referrer;
document.getElementById (' Backurl '). Value=refer;
</script>
"Http_referer"
Link to the URL address of the previous page of the current page. Not all user agents (browsers) will set this variable, and some can also modify http_referer manually. Therefore, this variable is not always true and correct.
Pay attention to Document.referrer; and "Http_referer" in the middle of a letter, but is a different concept of dongdong, please note the use of
JS in the use of referrer, back to the previous page
In the js write location.href = Document.referrer, you can achieve the jump to the previous page, so that users feel very good experience
But in IE referrer is not so satisfying, ah, ie will empty referrer
As we all know, web developers hate ie browsers, because IE does not support standards, the default behavior outside the standard and other browsers often inconsistent:
In IE with JavaScript to do jump, such as using Window.location.href = "http://www.google.com"; Google was unable to access the HTTP referrer requested by the browser because IE emptied the document.referrer
and other mainstream browsers Firefox and Chrome will retain referrer, which means that IE also enjoy the "ministerial" special treatment:
Copy Code code as follows:
if (/msie (\d+\.\d+);/.test (navigator.useragent)) {
var referlink = document.createelement (' a ');
Referlink.href = URL;
Document.body.appendChild (Referlink);
Referlink.click ();
}else {
location.href = URL;
}
This principle is to the Internet Explorer page secretly added a link, and then automatically point to this link, so referrer can be retained.
So we're depending on the different browsers, the need to consider the integrity of the code to become strong.