Modify the refer (GO) in HTTP

Source: Internet
Author: User

the importance of referrer

The HTTP request has a Referer header that indicates the source reference page of the current traffic. For example, click on www.sina.com.cn/sports/on a link to reach cctv.com home, then referrer is www.sina.com.cn/sports/. In JavaScript, we can get the same information through Document.referrer. With this information, we can know what channel the visitor came from to the current page. This is very important for web analytics, which tells us the distribution of traffic from different channels, as well as the keywords that users search for, all of which are obtained by analyzing this referrer information.

However, for a variety of reasons, sometimes the referrer read in JavaScript is an empty string. Here's a summary of the situations where you lose referrer.

Modify the Location object for page navigation

The Location object is a very useful object for page navigation. Because he allows you to change only one part of the URL. For example, switching from a CN domain name to a COM domain name, the rest is the same:

Window.location.hostname = "example.com";

However, by modifying the location for page navigation, you will lose referrer under IE.

Returns an empty string under ie5.5+

chrome3.0+,firefox3.5,opera9.6,safari3.2.2 normal return to source page

window.open Way to open a new window

Example:

<a href= "#" onclick= "window.open (' http://www.google.com ')" > Access google</a>

Clicking this link opens the Google site in a new window, and we can see the sent referrer by entering the following JS code in the Address bar.

Javascript:alert (Document.referrer)

Test results:

Returns an empty string under ie5.5+

chrome3.0+,firefox3.5,opera9.6,safari3.2.2 normal return to source page

If the same domain name jumps in this way, then we can access the Windoww.opener object to get the lost referrer information. The code is as follows:

<script type= "Text/javascript" >    var referrer = document.referrer;     if (! referrer) {        try  {            if  (window.opener) {                //  Under IE if cross-domain throws permission exception                //  Safari and Chrome under window.opener.location does not have any attributes                referrer = window.opener.location.href;            }        }          Catch (e) {}    }</script>

Cross-domain words are out of the way ~

Mouse Drag to open a new window

Mouse drag and drop is now very popular user habits, many browsers are built-in or can be plug-in way to support the mouse drag-and-drop browsing. But the pages opened in this way, basically all lose referrer. And, in this case, there is no way to use Window.opener to get the lost referrer.

Tested:

Maxthon2.5.2,firefox firegesture plug-in, chrome3.0+,opera9.6,safari3.2.

Click the Flash internal link

Click on the flash to reach another site, the situation of referrer is more messy.

IE, the value read through the client-side JavaScript document.referrer is empty, but if you use the traffic monitoring software to look at, you will find that in fact, the HTTP request in the Referer header is a value, this may be the IE implementation of the bug. At the same time, this value points to the address of the Flash file, not the source page.

Chrome4.0 Click Flash to reach the new window, referrer is also the address of the Flash file, not the source page.

Chrome3.0 and Safari3.2 are the same, they will lose referrer information.

Like Firefox, referrer's value is the address of the source page.

HTTPS jumps to HTTP

When you jump from an HTTPS Web site to an HTTP Web site, the browser does not send referrer. This big browser behaves the same.

For example, when we use Google Reader or gmail under HTTPS, click on a link to go to another site, so technically, such access and user directly typed URL access is no different.

impact of referrer loss on AD traffic monitoring

If the referrer is lost, Web Analytics will lose an important part of the information, especially for advertising traffic, there is no way to know the actual source. At present, many of the domestic use of Google AdSense ads site, are using the window.open way to open the advertising link, so IE will be lost referrer, and we know that IE is the largest market share of the browser, so its impact is very large. Many traffic statistics tools will therefore classify this portion of traffic as "direct traffic", which is equivalent to the user typing the URL directly.

In this case, The advertiser is required to add specific tracking parameters to the landing page URL when running the ad.

For example, a flash ad, the URL to arrive after the click is http://www.example.com/, in order to monitor this traffic from which channel, we can modify the landing URL of this run, change to http://www.example.com/?src= Sina, like this, then extracts this src parameter from the landing page using JavaScript code, so you can get the source information.

When running Google AdWords, the backend system has an "auto tag" option, and when this option is enabled, Google will automatically add a gclid parameter when it generates the landing page URL for all ads, which will allow Google Integration of analytics backstage and AdWords advertising back-office data. This allows you to know which ad traffic corresponds to which campaign, which ad source, and the ad keyword. And the above-mentioned ideas are actually similar. But Google automatically helped you make the URL changes.

The solution of referer under IE is empty

In IE under the window.location.href way jump, Referer value is empty. And in the tag inside the jump words referer will not be empty. Therefore, the following code can solve the IE problem

function gotourl (URL) {     if(window. VBArray) {         var gotolink = document.createelement (' a ');          = URL;         Document.body.appendChild (gotolink);         Gotolink. Click ();      Else {       = url;     }}
prevent browsers from Referer when accessing links

When we click on a link from one site to another, the browser adds a Referer value to the header to identify the source page of the visit. But this logo may leak the user's privacy, sometimes I do not want to let others know where I clicked in, can there be a means to let the browser do not send referer it?

    • Using the new HTML5 solution, rel= "Noreferrer" is used to declare that the properties of the connection are noreferrer and currently only chrome4+ support.
    • Use an intermediate page, but actually send referrer, such as using Google's connection to turn, noreferrer.js.
    • Use the JavaScript protocol link relay, see the instructions below.
Open a new window, equivalent to target= "_blank":
function Open_window (link) {     var arg = ' \u003cscript\u003elocation.replace (' +link+ ') \u003c/script\ u003e ';    window.open (' javascript:window.name; ') , Arg);}
turn to a connection, equivalent to target= "_self":
function Redirect (link) {     var arg = ' \u003cscript\u003etop.location.replace (' +link+ ') \u003c/script\ u003e ';     var iframe = document.createelement (' iframe ');    Iframe.src= ' javascript:window.name; ' ;    Iframe.name=arg;    Document.body.appendChild (IFRAME); }

Source: http://www.cnblogs.com/rubylouvre/p/3541411.html

Modify the refer (GO) in HTTP

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.