JS to determine if it is a mobile device for HTTP link redirection

Source: Internet
Author: User

1. Questions:

Users use mobile devices to access 127.0.0.1/yemian, automatically identify the phone and jump to 127.0.0.1/m/yemian

2, waiter, on the code:

//determine if it is a mobile devicevarUA =navigator.useragent;varUA ={Android:function() {// Android        returnUa.match (/android/i)?true:false; }, BlackBerry:function() {// BlackBerry        returnUa.match (/blackberry/i)?true:false; }, IOS:function(){//IOS        returnUa.match (/iphone|ipad|ipod/i)?true:false; },    //This is not really necessary, you can not judge this, after all, ie is an ancient thingWindows:function() {          returnUa.match (/iemobile/i)?true:false; }, IsMobile:function() {//Mobile Devices        returnUa. Android () | | Ua. BlackBerry () | | Ua. IOS () | |UA.    Windows (); }}
if (Us.ismobile ()) {    // Regular matches first/, redirect    location.replace (Location.href.replace (/\ , "/m/"));     }

3, Waiter, why not use Location.href to jump?

Location.replace will not save the URL before the jump, that is, the URL will not be placed in the history, so the return will not be valid

Use the difference: when you want to simulate the button click on the jump link, use Location.href

If you are simply HTTP redirect, that is to use Location.replace, as a csser, or to consider the user experience problem drops

Reprint Please specify: http://www.cnblogs.com/zhangmingze/p/5247296.html

JS to determine if it is a mobile device for HTTP link redirection

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.