Reasons for invalid JS document. Referral

Source: Internet
Author: User
Document directory
  • Modify location object for page navigation
  • Window. Open to open a new window
  • Drag the mouse to open a new window
  • Click the flash internal link
  • Jump from HTTPS to HTTP

From http://www.imkevinyang.com/2010/01/document-referrer%E4%B8%A2%E5%A4%B1%E7%9A%84%E5%87%A0%E4%B8%AA%E5%8E%9F%E5%9B%A0.html

In JS, you can use the following three methods to obtain the URL of the previous page:

1. Document. referrer

2、top.doc ument. referrer

3366100000000parent.doc ument. referrer

This can be implemented in both IE and Firefox.

However, if JavaScript function redirection is used in IE, all the above three methods obtain null values.


If the current page is nested with IFRAME, when you use Js in the IFRAME nested file to obtain the URL of the previous page of the current page, both 2 and 3 can be implemented.

But 1. Document. referrer won't work. It gets the address of the current page.

Reasons for document. referrer loss

Webanalytics document, Google Analytics, referrer, web analytics, Web analysis, incompatible, traffic analysis, empty string

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 in several scenarios lost by referrer 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:

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:

<A href = "#" onclick = "window. Open ('HTTP: // www.google.com ')"> access Google </a>

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.

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:

<SCRIPT type = "text/JavaScript"> var referrer = Document. referrer; If (! Referrer) {try {If (window. opener) {// in IE, if cross-origin is used, a permission exception is thrown. // in Safari and chrome, window. opener. location does not have any attribute referrer = Window. opener. location. href ;}} catch (e) {}}</SCRIPT>

Cross-origin is the same ~

Drag the mouse to open a new window

Mouse dragging is a very popular user habit nowadays. Many browsers are built in or can support mouse drag-and-drop browsing through plug-ins. However, basically all pages opened in this way lose referrer. In this case, you cannot use window. opener to obtain the lost referrer.

Tested:

Maxthon2.5.2, Firefox firegesture plugin, chrome3.0 +, opera9.6, safari3.2.

Click the flash internal link

When you click flash to reach another website, referrer is messy.

In ie, the document. the value read by the referrer is null. However, if you use the traffic monitoring software to check the value, you will find that the Referer packet header in the HTTP request actually has a value, this may be a bug in IE implementation. At the same time, this value points to the address of the Flash file, rather than the address of the source webpage.

When you click flash in chrome4.0 to reach a new window, referrer is also the address of the Flash file to which it points, rather than the address of the source webpage.

Chrome3.0 and safari3.2 are the same and both will lose the referrer information.

Opera is the same as Firefox. The referrer value is the address of the source webpage.

Jump from HTTPS to HTTP

When you jump from an HTTPS website to an HTTP website, the browser will not send a referrer. The behavior of these browsers is the same.

For example, when we use Google Reader or gmail under HTTPS and click a link to go to another website, technically speaking, there is no difference between such access and direct Website access.

Impact of referrer loss on ad traffic monitoring

If referrer is lost, web analytics will lose a very important part of the information, especially for advertising traffic, it is impossible to know the actual source. Currently, many websites in China that use Google Adsense advertisements use Windows. open way to open ad links, so IE will lose referrer, and we know that IE is currently the largest browser in the market, so its impact is great. Many traffic statistics tools classify this part of traffic into "direct traffic", which is equivalent to directly typing a URL.

In this case, the ad Releaser must add specific tracking parameters to the URL of the landing page when placing the ad.

For example, if a flash advertisement is clicked, what is the website address /? Src = sina. In this way, extract the SRC parameter using JavaScript code on the landing page to obtain the ad source information.

When Google adwords is launched, the background system has an "automatic tag" option. When this option is enabled, when Google generates the landing page URLs for all ads, A gclid parameter is automatically added, which can integrate the data in the Google Analytics background and the adwords advertisement background. In this way, you can know the ad series, AD sources, AD keywords, and other information corresponding to the ad traffic. The idea is similar to the one mentioned above. Google automatically modified the URL for you.

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.