Js determines that mobile phone access jumps to the mobile site, js jump

Source: Internet
Author: User

Js determines that mobile phone access jumps to the mobile site, js jump

  1. Method 1:

    <Script>

    If (navigator. platform. indexOf ('win32 ')! =-1 ){

    // Pc

    // Window. location. href = "computer website ";

    } Else {

    // Shouji

    Window. location. href = "Mobile Website ";

    }

    </Script>

  2. Method 2:

    <Script type = "text/javascript">

    Function browserRedirect (){

    Var sUserAgent = navigator. userAgent. toLowerCase ();

    Var bIsIpad = sUserAgent. match (/ipad/I) = "ipad ";

    Var bIsIphoneOs = sUserAgent. match (/iphone OS/I) = "iphone OS ";

    Var bIsMidp = sUserAgent. match (/midp/I) = "midp ";

    Var bIsUc7 = sUserAgent. match (/rv: 1.2.3.4/I) = "rv: 1.2.3.4 ";

    Var bIsUc = sUserAgent. match (/ucweb/I) = "ucweb ";

    Var bIsAndroid = sUserAgent. match (/android/I) = "android ";

    Var bIsCE = sUserAgent. match (/windows ce/I) = "windows ce ";

    Var bIsWM = sUserAgent. match (/windows mobile/I) = "windows mobile ";

    If (bIsIpad | bIsIphoneOs | bIsMidp | bIsUc7 | bIsUc | bIsAndroid | bIsCE | bIsWM ){

    Window. location. href = 'mobile website address ';

    } Else {

    Window. location = 'computer website address ';

    }

    }

    BrowserRedirect ();

    </Script>

  3. Method 3:

    <Script type = "text/javascript">

    Var mobileAgent = new Array ("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito ", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire ");

    Var browser = navigator. userAgent. toLowerCase ();

    Var isMobile = false;

    For (var I = 0; I <mobileAgent. length; I ++) {if (browser. indexOf (mobileAgent [I])! =-1) {isMobile = true;

    // Alert (mobileAgent [I]);

    Location. href = 'mobile web site ';

    Break ;}}

    </Script>

  4. Method 4:

    <? Php

    //// Put this section in the cell phone Station

    Header ("Cache-Control: no-cache ");

    Header ("Pragma: no-cache ");

    $ Ua = strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']);

    $ Uachar = "/(symbianos | android | Mac OS | ucweb | blackberry)/I ";

    If ($ ua! = ''&&! Preg_match ($ uachar, $ ua )){

    Echo 'window. location. href = "Computer address ";';

    Exit ();

    }

    ?>

    <? Php

    // Put this section in the website

    Header ("Cache-Control: no-cache ");

    Header ("Pragma: no-cache ");

    $ Ua = strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']);

    $ Uachar = "/(symbianos | android | Mac OS | ucweb | blackberry)/I ";

    If ($ ua! = ''& Preg_match ($ uachar, $ ua )){

    Echo 'window. location. href = "Mobile Address ";';

    Exit ();

    }

    ?>

  5. Method 5:

    <? Php

    Function UserAgent (){

    $ User_agent = (! Isset ($ _ SERVER ['HTTP _ USER_AGENT '])? FALSE: $ _ SERVER ['HTTP _ USER_AGENT '];

    Return $ user_agent;

    }

    // Mobile

    If (preg_match ("/(iphone | ipod | android)/I", strtolower (UserAgent () AND strstr (strtolower (UserAgent ()), 'webkit ')){

    Header ('location: Mobile Address ');

    Exit;

    } Else if (trim (UserAgent ()) = ''OR preg_match ("/(nokia | sony | ericsson | mot | htc | samsung | sgh | lg | philips | lenovo | ucweb | opera mobi | windows mobile | blackberry) /I ", strtolower (UserAgent ()))){

    Header ('location: Mobile Address ');

    Exit;

    } Else {// PC

    Header ("Location: web site ");

    }

    ?>

  6. Method 6: You can also download a file named uaredirect to your website;

    (Note: Put uaredirect in Baidu to search for the specific file address)

  • Note: The personal suggestion is to use the method provided by Baidu, which is simple and convenient and has little impact on the website opening speed.

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.