Javascript document. referrer browser support and failure summary _ basic knowledge-js tutorial

Source: Internet
Author: User
This article mainly introduces the document of javascript. referrer browser support, failure summary, more comprehensive document. referrer provides support for various browsers, when it will expire, and Referer information. For more information, see Traffic source in the Traffic Statistics Service. Traffic source is a sub-concept of access. In other words, when the access is established, the Traffic source of the landing page is the Traffic source of the access. Although there are many Traffic source types, unfortunately, based on the current JS, there are only two ways to obtain the Traffic source: document. referrer, window. opener. unfortunately, window. opener is not applicable in many scenarios, while document. the referrer is so weak that the traffic source cannot be accurately determined in many scenarios.

Overwrite document. referrer

In terms of usage, document. referrer wants to track browser behavior. If A page A is opened, user operations and JS Code may occur on the browser side.

First, let's take A look at the operations that A may perform when opening page:

1 Enter the address of A in the address bar.
2 From Page B, left-click link A to jump to page.
3 Right-click link A on page B and open it in A new window.
4 Right-click link A from page B and open it in the new tab.
5 Drag link A to the address bar
6 Drag link A to the tab bar.
7 Use the browser's forward and backward buttons

Note that the link here refers to the tag, but if there is an event or target, it should be another matter.

Possible ways for JS to open a page:

1
Modify window. location
2
Use window. open
3
Click flash

The above lists some methods for the client to open the page. In addition, if the server redirection technology is used, page A can also be presented to the visitor.

The following describes how document. referrer performs in browser tests:

Serial number Scenario
IE8.0 FF3.6 FF4.0 Chrome
1 Enter the address of A in the address bar. ""
""
"" ""
2 From Page B, left-click link A, and page A replaces page B (target = '_ self ')
3 From Page B, left-click link A. A is displayed in A new window (target = '_ blank ')
3 Right-click link A on page B and open it in A new window. ""
4 Right-click link A from page B and open it in the new tab. ""
5 Drag link A to the address bar / "" "" ""
6 Drag link A to the tab bar "" "" "" ""
7 Use the browser's forward and backward buttons Persistence Persistence Persistence Persistence
8 Modify window. location to open page A (same domain) ""
9 Use window. open to open page ""
10 Click flash to open page
11 Server redirection to page "" "" "" ""

"" Indicates an empty string, and √ indicates that the source page can be correctly identified. Persistence means that the referrer of the page will not be changed after the forward and backward operations are used. From this table, we can see that document. referrer can cover about half of the case. However, some common operations, such as dragging the link to the label bar with the mouse, and moving forward and backward, cannot be correctly handled.

Document. referrer Source

When the browser requests page A from the server, it sends an HTTP request. The request Header contains the Referer attribute. After receiving the request, the server can extract the Referer in the Header to determine the page from which the visitor initiated the request.

In general, what is the Referer in the Header sent when the browser requests A? What is the value of document. referre after getting A page. Is the Header of A request page. The document. referre of A is http: // localhost/Test/B .html.

If the Header does not contain a Referre, it is assigned a null string when document. referre is used for retrieval.

About HTTPS requests

If you click the HTTPS link on a common HTTP page, you can attach Referer information to the https request header, and then you can still use document on the HTTPS page. referre.

Similarly, if you click another https link on an HTTPS page, you can attach the Referer information to the request header.

However, if you click an http link from an https page, the http request header cannot contain information about the https page, this may be due to a protection measure for https pages.

Counterfeit Referer information

According to the above description, document. referre originated from the Referer in the Header. If you want to modify the value of document. referre, theoretically, you only need to modify the request Header. You can replace the existing Referer in the Header with the desired value. If not, you can add a Referer.

At the client side, it is very easy to tamper with the Header. Before an http request is sent to a page, you can use the packet capture tool to intercept it, analyze the initial information, and modify the Referre.

After searching, you can use the RefControl plug-in to conveniently modify FireFox. In short, it is easy to cheat the Traffic source.

Page force Refresh

Soon after writing, I found that a page Jump method was missing, that is, to force the specified page to refresh in the meta tag of html. For example, write data in B .html

The Code is as follows:


After five seconds, the browser will automatically initiate a page request to the server.

After testing, in IE8, ff3.6-ff4.0, there will be no refererinformation, but chromeide is able to add B .html as a Referer to the header.
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.