小东博客

自动跳转手机版||电脑访问手机版自动跳转电脑版

手机访问电脑版自动跳转手机版代码


<script type="text/javascript">
//手机跳转
var browser = {
    versions: function() {
        var u = navigator.userAgent;
        var app = navigator.appVersion;
        return {
            trident: u.indexOf('Trident') > -1,
            presto: u.indexOf('Presto') > -1,
            pwebkit: 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浏览器                
            iPhone: u.indexOf('iPhone') > -1,
            //是否为iPhone或者QQHD浏览器                
            iPad: u.indexOf('iPad') > -1,
            //是否iPad                
            webApp: u.indexOf('Safari') == -1
            //是否web应该程序,没有头部与底部 

        };

    } ()

}
var argStr = location.search;
if (browser.versions.iPhone || browser.versions.android) {
    //用手机浏览
    if (argStr == "")
    {
        window.open('http://lxd.mobi/', '_self', '', 'true');

    }

}
</script>



电脑访问手机版自动跳转电脑版


<script type="text/javascript">
var browser={
	versions:function(){
		var u=navigator.userAgent;
		var app=navigator.appVersion;
		return{
			trident:u.indexOf('Trident')>-1,
			presto:u.indexOf('Presto')>-1,
			pwebkit: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浏览器                
			iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器                
			iPad: u.indexOf('iPad') > -1, //是否iPad                
			webApp: u.indexOf('Safari') == -1 //是否web应该程序,没有头部与底部 
			};
		}()
	}
	
	
	var argStr=location.search;
	
	if(browser.versions.iPhone||browser.versions.android){
		//window.open('phone.html','_self','','true');
	}
	else
	{
		if(argStr=="")
		{
			window.open('http://www.lxd.cc/','_self','','true');
		}
	}</script>


码字很辛苦,转载请注明来自.小东博客 .《自动跳转手机版||电脑访问手机版自动跳转电脑版 》

评论

  1. 博客大巴

    感谢楼主分享

    回复
    2014-12-21 14:04
  2. 游客

    哈哈,好东西,拿走了

    回复
    2014-11-22 17:00