随着互联网的发展现在有很多站长不段地去追求手机网站,建好一个PC网站,现如何把PC站实现让手机跳转成手机站的呢?今天柏思网络老钟就分享一下关于如何JS实现跳转手机站,现在用手机访问网站的时候,如果让PC网站自动跳转到WAP网站呢,其实只要在<head></head>之间加一段JS代码就可以实现了。
<script>
var bs={
versions:function(){
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/)||!!u.match(/AppleWebKit/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -1, //是否iPad
webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部
};
}(),
language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
if(bs.versions.mobile){
if(bs.versions.android||bs.versions.iPhone||bs.versions.iPad||bs.versions.ios){
window.location.href="手机域名";
}
}
</script>
把手机WAP地址【手机域名】改成你的WAP站地址就可以了。
以上来自柏思网络老钟分享,希望能帮到各位,如何不明白的地方或更多了解,请与柏思网络商务联系。