第一种方式:
从M 跳转到PC
<head>
<script>
function isPC() {
for (var n = navigator.userAgent, i = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod", "windows mobile"], o = !0, e = 0; e < i.length; e++)
if (n.indexOf(i[e]) > 0) {
o = !1;
break
}
return o
}
if (isPC()) {
//跳转后没有后退功能
window.location.replace("http://www.baidu.com/pc_index.html")
}
</script>
</head>
从PC 跳转到M
<head>
<script>
function IsM() {
var userAgentInfo = navigator.userAgent;
var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone","iPad", "iPod","windows mobile"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
if(!IsM()){
//跳转后没有后退功能
window.location.replace("http://www.baidu.com/m_index.html")
}
</script>
</head>
第二种方式
**#注意:第二种方式是获取pc/m 两端同页面相同的名称。比如:pc端、移动端页面都叫 contetn.vue **
pc跳转m
(function() {
var sUserAgent = navigator.userAgent.toLowerCase();
var path = this.location.pathname;
if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(sUserAgent)) {
//跳转移动端页面
window.location.replace(`http://www.baidu.com.com${path}`);//跳转后没有后退功能
return;
}
})();
m 跳转 pc
(function() {
var path = this.location.pathname;
function isPC() {
for (var n = navigator.userAgent, i = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod", "windows mobile"], o = !0, e = 0; e < i.length; e++)
if (n.indexOf(i[e]) > 0) {
o = !1;
break
}
return o
}
if (isPC()) {
window.location.replace(`http://www.baidu.com.com${path}`);//跳转后没有后退功能
}
})();