PC站 www.mysite.com 手机站 app.mysite.com
现在想实现在手机端,,比如微信上面把地址www.mysite.com发给朋友,他打开,直接跳到手机站 app.mysite.com
搜索到一串代码
- function getMCookie(objName) {
- var arrStr = document.cookie.split("; ");
- for (var i = 0; i < arrStr.length; i++) {
- var temp = arrStr[i].split("=");
- if (temp[0] == objName) {
- return unescape(temp[1]);
- }
- }
- return "";
- }
-
- 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) {
- location.href = ‘http://app.mysite.com’; //字符串内填写可访问的手机版域名,例如m.xxx.com,如果没有域名可直接填写/m/index.html
- }
- }
- var pageurl = window.location.search;
- if (pageurl == ‘?m2w’) {
- document.cookie = "m2wcookie=" + escape("1");
- }
- if (getMCookie("m2wcookie") != "1") browserRedirect();
复制代码
手机上浏览器可以实现跳转,,,微信上面打开,不会跳转
请教各位大佬,,怎么实现微信上面打开PC站,自动跳转手机站 |