Referrer in JS return to the previous page using the introduction _javascript tips

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.