Complete js Code:
Copy codeThe Code is as follows:
<Script language = "javascript">
Var refer = document. referrer;
Document. getElementById ('backurl'). value = refer;
</Script>
"HTTP_REFERER"
The URL of the previous page that is linked to the current page. Not all user proxies (browsers) will set this variable, and some can also manually modify HTTP_REFERER. Therefore, this variable is not always true and correct.
Note that there is a letter between document. referrer; and "HTTP_REFERER", but they are different concepts.
Use referrer in js and return to the previous page
Write location. href = document. referrer; In js to jump to the previous page.
But in IE, referrer is not so satisfactory. IE will clear the referrer
As we all know, our web developers hate IE, because IE does not support standards, and default behaviors outside the standards are often different from those in other browsers:
In IE, javascript is used for redirection, such as window. location. href = "http://www.google.com"; google cannot get the HTTP referrer requested by the browser, because IE clears document. referrer
Referrer will be retained in other mainstream browsers Firefox and Chrome, which means IE will enjoy the special "ministerial level:
Copy codeThe Code is 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;
}
The principle is to secretly add a link to the page of IE browser, and then click the link automatically, so the referrer will be retained.
Therefore, we must consider the completeness of different browsers to make the code stronger.