JavaScript document.referrer in a variety of browsers test results _ Basics

Source: Internet
Author: User

Some time ago need to get the source of the page through JavaScript, this operation is very simple, using document.referrer can be obtained. However, there are still a lot of surprises in the application, and here is a simple arrangement.

The first problem you encounter is that when you go from an HTTPS page to an HTTP page, the Document.referrer value is empty. For security reasons, a number of important pages on many sites (such as Taobao's login page) use the HTTPS protocol. If an unregistered user clicks a link to page B (HTTP page) on page A (HTTP page), but page B requires the user to log in, so first jump to the login page (HTTPS page), and then jump back to B (HTTP page), then you will find no document on page b . referrer. That is, if you want to restore the user access path based on referrer, if there are HTTP pages in the path and HTTPS pages, the path will be broken off from HTTPS to HTTP.

The root of this problem is the browser's security policy, and JavaScript does not seem to have a particularly good solution. A roundabout idea is to use Window.name to write the URL of the current page to Window.name in the HTTPS page and then read it on the next page (HTTP page).

In addition to this situation, can other page jumps normally take to document.referrer? I did a search and found that there was a list of people here, but not very full, for example, without the IE6 of the dead. So he started, installed in the virtual machine N Browser, the various conditions have been tested (this is really a physical work), the results are shown in the following table:

Operation IE6 IE7 IE8 IE9 Firefox Chrome Opera Safari
Enter the URL directly in the address bar “” “” “” “” “” “” “” “”
Access URLs from bookmarks “” “” “” “” “” “” “” “”
Click the hyperlink from page A and jump to page B (target= "_self")
Click the hyperlink from page A and jump to page B (target= "_blank")
Right-click a hyperlink from page A, and open page B in a new tab page - “”
Right-click a hyperlink from page A, and open page B in a new window “”
Drag Link to address bar “” Cannot drag Cannot drag “” “” “” “” “”
Drag Link to tab bar - “” “” “” “” “” “” “”
Use the browser's forward and rewind buttons
JS Modified Location.href “” “” “”
JS Use window.open “” “” “” “”
Server redirection (302 jumps) Pre-orientation Page Pre-orientation Page Pre-orientation Page Pre-orientation Page Pre-orientation Page Pre-orientation Page Pre-orientation Page Pre-orientation Page
Page Meta Refresh “” “” “” “” “” Turn page Turn page Turn page

"√" in the table above indicates that the referrer is normal and "" means referrer is empty.

In addition to IE, other browsers are currently available on the official web to download the latest version of which Safari also tested the Windows version and MAC version, the same conclusion.

In addition, there are some cases not tested, such as clicking on Flash jump under the browser can keep referrer and so on.

Most of the above table is in line with expectations, but there seem to be several things to note:

1, in Safari, the right key to open the link will lose referrer;
2, in IE, modify Location.href or use window.open to open the page will be lost referrer (ie 9 with a few exceptions, the use of Location.href jump will not lose referrer);
3, when using meta jump, Ie/firefox will lose referrer.

Finally, a simple conclusion: if you need to collect page access through Document.referrer, it is best not to use JS jump or open a new window, do not use meta jump.

Related Article

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.