Detailed referer parsing in javascript operations _ javascript skills

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


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.