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