This article mainly introduces the javascript referer operation in detail. If you need it, please refer to it and hope to help you.
Referrer importance
The HTTP request contains a referer header, which is used to specify the reference page for the current traffic source. For example. In Javascript, we can use document. referrer to obtain the same information. With this information, we can know the channel through which visitors come to the current page. This is very important for Web Analytics, which can tell us the distribution of traffic brought about by different channels, as well as keywords for user search, all are obtained by analyzing the referrer information.
However, for various reasons, sometimes the referrer read in Javascript is a null string. Next we will summarize the situations in which referrer will be lost.
Modify Location object for page navigation
Location object is a very practical object for page navigation. Because it allows you to change only some of the URLs. For example, to switch from a cn domain name to a com domain name, the other parts remain unchanged:
The Code is as follows:
Window. location. hostname = "example.com ";
However, modifying the Location for page navigation will lead to the loss of Referrer in IE.
IE5.5 + returns an empty string
Chrome3.0 +, Firefox3.5, Opera9.6, and Safari3.2.2 are returned to the source webpage normally.
Window. open to open a new window
Example:
The Code is as follows:
Access Google
Click this link to open the Google website in a new window. Enter the following js code in the address bar to view the referrer sent.
The Code is as follows:
Javascript: alert (document. referrer)
Test results:
IE5.5 + returns an empty string
Chrome3.0 +, Firefox3.5, Opera9.6, and Safari3.2.2 are returned to the source webpage normally.
If this method is used for redirection under the same domain name, we can access the windoww. opener object to obtain the lost referrer information. The Code is as follows:
The Code is as follows: