您现在的位置: 首页 > 新闻 > 建站常识

厦门手机网站建设和PC网站建设自动识别客户端的办法

来源:厦门网络公司发布时间:2020-05-07热度:5096

很多企业网站都需要作一个手机版,所有网站手机和电脑都可以打开,只是现在的智能手机不能很好的兼容电脑版的网页。手机版的网站需要简单,以文字为主,才能很好的兼容。可以在网站的首页设置一个程序来判断用户是手机端还是电脑。如果是手机端,直接中转到手机端 。如果是PC端 直接中转到PC端。

在网站的首页插入入下代码。

<scripttype='text/javascript'>

functionbrowserRedirect(){

varsUserAgent=navigator.userAgent.toLowerCase();

varbIsIpad=sUserAgent.match(/ipad/i)=='ipad';

varbIsIphoneOs=sUserAgent.match(/iphoneos/i)=='iphoneos';

varbIsMidp=sUserAgent.match(/midp/i)=='midp';

varbIsUc7=sUserAgent.match(/rv:1.2.3.4/i)=='rv:1.2.3.4';

varbIsUc=sUserAgent.match(/ucweb/i)=='ucweb';

varbIsAndroid=sUserAgent.match(/android/i)=='android';

varbIsCE=sUserAgent.match(/windowsce/i)=='windowsce';

varbIsWM=sUserAgent.match(/windowsmobile/i)=='windowsmobile';

if(!(bIsIpad||bIsIphoneOs||bIsMidp||bIsUc7||bIsUc||bIsAndroid||bIsCE||bIsWM)){

window.location.href=B页面;

}

}

browserRedirect();

</script>

<scripttype='text/javascript'>uaredirect('<Ahref='http://www.itwuhan.com/wap/','http://www.itwuhan.com/index.html');http://www.itwuhan.com/wap/','http://www.itwuhan.com/index.html');</script>

<metahttp-equiv='Content-Type'content='text/html;charset=gb2312'/>

本文来源:http://www.ycwebs.com/news/show-972.html