How to achieve mobile Browsers without displaying advertisements on the pc side _ javascript skills

Source: Internet
Author: User
With the development of mobile networks, more and more people use mobile phones and other mobile terminals to browse Web pages for office work. If a large Alliance advertisement is displayed when the mobile phone opens the page, the user experience will be very poor, after some research, the following method is used to realize that mobile Browsers Do Not Display PC advertisements. I wrote a blog post about built-in browsers that do not display Alliance ads.

Determine whether the current browser is a built-in browser based on window. navigator. userAgent.

window.navigator.userAgent=='micromessenger'

The content to be shared today is similar, because previously we only considered browser adaptation, and turned back to the mobile browser to open the site and found the adaptation problem.
Some consortium automatically blocks mobile terminals, but some consortium cannot block them, so they can only be judged manually.

Determine the source based on the browser userAgent

UserAgent judgment for Android devices

navigator.userAgent.match(/Android/i)

Iphone userAgent judgment

navigator.userAgent.indexOf('iPhone')!=-1

UserAgent judgment for ipad devices

navigator.userAgent.indexOf('iPad') != -1

Ipod device userAgent judgment

navigator.userAgent.indexOf('iPod') != -1

Add the built-in browser judgment method.

function isWeiXin() {    var ua = window.navigator.userAgent.toLowerCase();    if (ua.match(/MicroMessenger/i) == 'micromessenger') {      return true;    } else {      return false;    } }

Shielded, mobile phone (except winphone devices), ipod

If (! IsWeiXin ()&&! (Navigator. userAgent. match (/Android/I) | (navigator. userAgent. indexOf ('iphone ')! =-1) | (navigator. userAgent. indexOf ('ipod ')! =-1) | (navigator. userAgent. indexOf ('ipad ')! =-1) {var sogou_ad_id = 4767753; // consortium advertising billing id}
Related Article

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.