HTML用JS判断PC和WAP端自适应域名转换跳转

单在html前端<head>里添加JS代码即可

PC端:

<script>
(function () {
if (navigator.userAgent.match(
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
)) {
if (window.location.search.split('=')[1] != undefined) {
var destinationUrl = 'pc域名' + window.location.search;
if (location.href.split("zlkdatasys/mct/")[1] !== undefined) {
var _source = location.href.split("zlkdatasys/mct/")[1].split("/")[0];
destinationUrl += '&source=' + _source;
}
window.location.href = destinationUrl;
} else {
window.location.href = 'map域名'
}
}
}());
</script>

 

 

WAP端:

<script>
//非移动端,页面跳转到PC端
(function () {
if (!(navigator.userAgent.match(
/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
))) {
if (window.location.search.split('=')[1] != undefined) {
var destinationUrl = 'pc域名' + window.location.search;
if (location.href.split("zlkdatasys/mct/")[1] !== undefined) {
var _source = location.href.split("zlkdatasys/mct/")[1].split("/")[0];
destinationUrl += '&source=' + _source;
}
window.location.href = destinationUrl;
} else {
window.location.href = 'pc域名'
}
}
}());
//屏幕适应
(function (win, doc) {
if (!win.addEventListener) return;
var html = document.documentElement;

function setFont() {
var w = html.clientWidth, h = html.clientHeight;
html.style.fontSize = w > h ? (w / 1334 * 100) + "px" : (w / 750 * 100) + "px";
}

setFont();
setTimeout(function () {
setFont();
}, 300);
doc.addEventListener('DOMContentLoaded', setFont, false);
win.addEventListener('resize', setFont, false);
win.addEventListener('load', setFont, false);
})(window, document);
</script>

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发
  • ZSBT666

    昵称

  • 取消
    昵称