Online shopping does not forget to learn-use JavaScript to classify and guide website access sources

Source: Internet
Author: User

During the holidays, the desire to buy a car wash device doubles, and Labor Day is no exception. I bought a car wash device online yesterday and accidentally enteredSanxueAlthough the search results show its primary domain name, you can click it to directly go to an inner page of the website (/Xicheqi), Repeated times, still so, from the design of this page, it seems that there are some differences, but a good master domain name does not need to jump directly to the inner page what? So I modified the address in the address bar and changed it to the primary domain name. Then I visited the website and found that the website has a home page. However, the home page design is very simple, my God, why.

After several searches, I finally got the answer: this is a website that promotes car washing devices. The home page and the internal page have different division of labor. The internal page is responsible for displaying goods and guiding purchases, and the home page is responsible for Seo. This form is not uncommon in the promotion websites, but I am interested in: Why did I open the home page in the search results and go to the inner page, but did not jump to the home page in the browser?

Review elements, found such a paragraphCode:

1 VaRRegexp = /\. (sogou | Soso | Baidu | Google | youdao | Yahoo | bing | 118114 | biso | gougou | ifeng | IVC | Sooule | niuhu | biso )(\. [a-z0-9 \-] + }\//IG;2 VaRWhere =Document. referrer;3 If(Regexp. Test (where ))4 {5Window. Location. href = 'HTTP: // www.threesnotescom/xicheqi /'6}

The truth is that this is a javascript code that redirects pages only for links from search results. The content of the Code is easy to understand, and similar code is not difficult to write. However, the above Code is different from the various code that directly jumps in terms of requirement solution. Generally, there are three sources of access to a website:Direct access, access through search engines, and through external links. When a website needs to differentiate and direct the three access sources, direct redirect obviously cannot solve the problem, and there is no parameter for access from outside the site to the site. Therefore, this type of source classification derived from promotional websites is a good method.

The Code copied from the sanxue website only supports direct access and search engine access classification. if the referrer value is null, rewrite another JavaScript code segment that classifies the three access sources for backup.

 1   VaR Regexp = /\. (sogou | Soso | Baidu | Google | youdao | Yahoo | bing | 118114 | biso | gougou | ifeng | IVC | Sooule | niuhu | biso | threesnow )(\. [a-z0-9 \-] + }\// IG;  2   VaR Where = Document. referrer;  3   4   If (Where = Null  )  5  {  6       //  Direct Access  7 Window. Location. href = 'HTTP: // www.cnblogs.com /' 8   }  9   Else   If  (Regexp. Test (where ))  10   {  11       //  Access through search engines  12 Window. Location. href = 'HTTP: // www.cnblogs.com/cnliu /' 13   }  14   Else  15   {  16       //  Access through external links  17 Window. Location. href = 'HTTP: // www.cnblogs.com/cnliu/archive/2011/07/25/evaluate-15-pages-of-university.html' 18 }

 

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.