电脑端网站在手机访问时,指定转向另一个页面的JS代码

在有些时候,我们需要在手机访问网站时,把网站指向另一个网站或另一个目录,这时候,我们需要在默认首页上加一代JS,就可实在。如下代码,网址改成需要指向的网站或目录,保存成JS文件,放在网站的首页头部即可。

var domain = ["http://www.gzhsez.cn"];
var al = new Array("iPad", "iPhone", "Android", "X11", "MIDP",
"Opera Mobi", "Opera Mini", "BlackBerry", "HP iPAQ", "IEMobile",
"MSIEMobile", "Windows Phone", "HTC", "LG", "MOT", "Nokia",
"Symbian", "Fennec", "Maemo", "Tear", "Midori", "armv",
"Windows CE", "WindowsCE", "Smartphone", "240x320", "176x220",
"320x320", "160x160", "webOS", "Palm", "Sagem", "Samsung", "SGH",
"Siemens", "SonyEricsson", "MMP", "UCWEB");
function toUrl() {
var i = parseInt(Math.random() * (domain.length));
window.location.href = domain[i];
}
function checkUA() {
var userAgent = navigator.userAgent;
var ifWap = "";
for ( var mobile in al) {
var m = al[mobile];
var ms = new RegExp(m.toLowerCase());
if (ms.test(userAgent.toLowerCase())) {
switch (m.toLowerCase()) {
case "ipad":
ifWap = "ipad";
toUrl();
break;
case "iphone":
ifWap = "iphone";
toUrl();
break;
default:
ifWap = "other";
toUrl();
break;
}
} else {
ifWap = "PC";
}
if (ifWap != "" && ifWap != "PC")
break;
}
}
checkUA();

未经允许不得转载:宅男福利社 » 电脑端网站在手机访问时,指定转向另一个页面的JS代码

赞 (1)

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址