JavaScript(PHP)如何用移动端设备访问,自动跳转到移动版页面?

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Aaroun/article/details/81948822

根据设备是否是移动设备自动跳转到对应的页面,如果是pc端就显示pc端的页面,如果是移动端就显示移动端的页面。

下面就为大家详细介绍下!只需要把下面这块代码贴上去就可以了!

<script>
(function(){
	var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
	 
	var browser = navigator.userAgent.toLowerCase();
	 
	var isMobile = false;
	 
	for (var i = 0; i < mobileAgent.length; i++) {
	    if (browser.indexOf(mobileAgent[i]) != -1) {
	        isMobile = true;
	 
	         //alert(mobileAgent[i]);
	 
	        location.href = 'http://www.yimudin/windex.php';
	 
	        break;
	    }
     }
})();
</script>

猜你喜欢

转载自blog.csdn.net/Aaroun/article/details/81948822