Using location. href in IE to obtain referer value _ javascript skills

Source: Internet
Author: User
Window is used in IE. location. if the href method redirects, the referer value will not be blank if the referer value is empty in tag a. The following shows the specific implementation Code recently, the company website needs to collect statistics on the pages on which users enter the registration page. In the beginning, it is simply obtained through $ _ SERVER ['HTTP _ referer'] (php) on the SERVER side. However, we found that many registered users do not have the referer value. Later, we checked that the referer value is blank if window. location. href is used for redirect in IE. The referer will not be empty if the redirection in the tag is used. Therefore, you can solve this IE problem through the code below:

Function gotoUrl (url) {if (document. all) {var gotoLink = document. createElement ('A'); gotoLink. href = url; document. body. appendChild (gotoLink); gotoLink. click ();} else window. location. href = url ;}

The principle is to create a tag, set the url address to jump to, and then trigger the click event.

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.