http://www.html-js.com/article/2677
Now many sites are divided into two versions, a PC end of a mobile (except the response), for these two versions, you need to access the device to judge, if it is a PC, direct access to the PC website, or access to the mobile site.
For this problem can be resolved by judging UA, the front-end JS can judge, the back-end judgment is OK, here we mainly discuss how to deal with JS.
If we have a website, the PC is accessed via www.test.com, and the mobile is accessed through m.test.com. What we need to do is to jump directly to m.test.com when the www.test.com is accessed by the mobile side. At this point we just have to deal with it, add the following JS code to the head of the page:
(function(){var URL= Location. href;Replace www.test.com with your domainIf((URL.IndexOf(' Www.test.com ')!= -1 ) && navigator.useragentmatch (/(iphone|ipod| Android|ios|ipad)/i) {location.href = Span class= "token string" > ' http://m.test.com ' ; }})
However, in most cases it is not just that simple to jump directly from www.test.com to m.test.com. Our site in addition to the hostname part, followed by the following, such as: www.test.com/list/98/, for such a url,pc directly such access, for mobile, need to through m.test.com/list/98/can show a better effect.
Then, you can use the regular to handle, when the mobile access, we replace "http://www" with "http://m" (Colon is the English colon), and then update the page to see the page on the mobile side of the effect of rendering. The specific code is as follows:
(function(){var URL= Location. href;Replace www.test.com with your domainIf((URL.IndexOf(' Www.test.com ')!=-1)&& Navigator. useragent.Match(/(iphone|ipod| Android|ios|ipad)/i) {var newurl = Urlreplace ( ' http://www ') Span class= "token punctuation", ' http://m ' ) ; Location.href = Newurl }})
Ok, the above is the mobile and PC-side website access issues.
JavaScript judges Mobile and PC-side access to different websites