pc跳移動
function checkDevice() {
var flag = "";
var agent = navigator.userAgent.toLowerCase();
var ipadKeywords = ["ipad"];
var mobileKeywords = ["android", "iphone", "windows phone"];
//排除 Windows 桌面系統(tǒng)
if (
!(agent.indexOf("windows nt") > -1) ||
(agent.indexOf("windows nt") > -1 &&
agent.indexOf("compatible; msie 9.0;") > -1)
) {
//排除蘋果桌面系統(tǒng)
if (
!(agent.indexOf("windows nt") > -1) &&
!(agent.indexOf("macintosh") > -1)
) {
for (var item in ipadKeywords) {
if (agent.indexOf(ipadKeywords[item]) > -1) {
flag = "ipad";
break;
}
}
for (var item in mobileKeywords) {
if (agent.indexOf(mobileKeywords[item]) > -1) {
flag = "mobile";
break;
}
}
}
}
return flag;
}
var device = checkDevice();
var isIPad = device == "ipad";
var isMobile = device == "mobile";
var hmsr = "";
var href = window.location.host;
var pathname = window.location.pathname;
var search = window.location.search;
var loc=pathname.substring(1);
console.log(loc);
if (isMobile) {
window.location.href = window.location.href.replace("www", "m");
//window.location.+loc;
} else {
}
移動跳pc
function checkDevice() {
var flag = "";
var agent = navigator.userAgent.toLowerCase();
var ipadKeywords = ["ipad"];
var mobileKeywords = ["android", "iphone", "windows phone"];
//排除 Windows 桌面系統(tǒng)
if (
!(agent.indexOf("windows nt") > -1) ||
(agent.indexOf("windows nt") > -1 &&
agent.indexOf("compatible; msie 9.0;") > -1)
) {
//排除蘋果桌面系統(tǒng)
if (
!(agent.indexOf("windows nt") > -1) &&
!(agent.indexOf("macintosh") > -1)
) {
for (var item in ipadKeywords) {
if (agent.indexOf(ipadKeywords[item]) > -1) {
flag = "ipad";
break;
}
}
for (var item in mobileKeywords) {
if (agent.indexOf(mobileKeywords[item]) > -1) {
flag = "mobile";
break;
}
}
}
}
return flag;
}
var device = checkDevice();
var isIPad = device == "ipad";
var isMobile = device == "mobile";
var hmsr = "";
var href = window.location.host;
var pathname = window.location.pathname;
var search = window.location.search;
var loc=pathname.substring(0);
console.log(loc);
if (isMobile) {
} else {
window.location.href = window.location.href.replace("m.", "www.");
// window.location.+loc;
}