1
2
3
4
5
6
7
8
9
10
11
if ((navigator.userAgent.match(/(iPhone|iPod|Android|Windows Phone)/i))) {
if(window.location.href.indexOf("lapin.ithome.com")>0)
{
var reg = new RegExp(/lapin.ithome.com\/html\/.*?\/(\d+).htm/i); var r = window.location.href.match(reg); location.replace("http://lapin.ithome.com/wap/" + r[1] + ".htm");
}
else if (window.location.href.indexOf("/html/")>0)
{
var reg = new RegExp(/www.ithome.com\/html\/.*?\/(\d+).htm/i); var r = window.location.href.match(reg); location.replace("https://m.ithome.com/html/" + r[1] + ".htm");
}
}
if (self != top) top.location.href = window.location.href

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//是否是移动端
function is_mobile() {
var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
var u = navigator.userAgent;
if (null == u) {
return true;
}
var result = regex_match.exec(u);

if (null == result) {
return false
} else {
return true
}
}
<script src="/content/js/is_mobile.js"></script>
<script language="javascript">
if (is_mobile()) {
document.location.href = 'https://m.lapin365.com';
}
</script>