js complete code:
< script language="javascript">
var refer=document.referrer;
document.getElementById('backurl').value=refer;
"HTTP_REFERER" The URL address of the previous page linked to 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.
Note that there is one letter difference between document.referrer; and "HTTP_REFERER", but they are different concepts. Please pay attention to using referrer in
js to return to the previous page. Page Write location.href = document.referrer; in js to jump to the previous page, making the user feel a good experience
But in IE The referrer is not so satisfactory, IE will clear the referrer
As we all know, we web developers hate the IE browser because IE does not support standards, and the default behavior outside the standards is often inconsistent with other browsers:
Use javascript to make a jump in IE, for example, use window.location.href = “http://www.google.com”; Google cannot get the HTTP referrer requested by the browser because IE clears document.referrer
The other mainstream browsers Firefox and Chrome will retain the referrer, which means that IE will enjoy "ministerial" special treatment again:
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;
}
The principle is to secretly add a link to the IE browser page, and then automatically click on the link, so the referrer can be retained.
So we must consider the different situations of different browsers completely to make the code strong.