Javascript 设备跳转

本文介绍了一种设备跳转列表的优化方案,通过检测用户代理字符串来判断是否为移动设备,并进行相应的页面跳转,确保了移动用户的浏览体验。代码实现了对多种移动设备的识别,包括iOS、Android、黑莓等,并针对不同情况调整URL,实现到移动版页面的跳转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

做个记录,之后复制

//设备跳转列表
(function go_mobile(){
	
	var ua_list = ['UCWEB','iPh',"iPhone","iPod","Android","dream","CUPCAKE","blackberry9500","blackberry9530","blackberry9520","blackberry9550","blackberry9800","webOS","incognito","webmate","s8000","bada","Meizu M8",'LG-TU915 Obigo','LGE VX','webOS','Nokia5800','IEMobile'];
	var ua_list_length = ua_list.length,
	ua = window.navigator.userAgent,
	i=0;
	var href = location.href;
	for(i=0; i<ua_list_length; i++){	
		if(ua.indexOf(ua_list[i]) !== -1
			&& ua.indexOf('IEMobile') === -1
			&& ua.indexOf('MSIE') === -1){
			if(typeof mobileUrl == "undefined"){
				var href_arr = href.split('/');
				var href_arr_length = href_arr.length;
				var script_name_real = href_arr[href_arr_length-1];
				if (href.indexOf('http://tools.2345.com/astro/susan.htm') !== -1) {
					location.href = '/m/susan/';
					break
				}		
				if(script_name_real.indexOf('_') && script_name_real.indexOf('suanming_zw')==-1 && script_name_real.indexOf('study_tizhong') == -1 && href.indexOf('miyu') == -1){
				    var script_name = script_name_real.split('_');
					href = href.replace(script_name_real, script_name[0]);
				}
				href = href.replace('http://tools.2345.com', '');
				href = href.replace('http://zgjm.2345.com', '');
				href = href.replace('http://wapzgjm.2345.com', '');
				// https也转换
				href = href.replace('https://tools.2345.com', '');
				href = href.replace('https://zgjm.2345.com', '');
				href = href.replace('https://wapzgjm.2345.com', '');
				location.href='/m'+href;
				break;
			}
			else
			{
				location.href=mobileUrl;
				break;				
			}
		}
	}
})();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

跨端蝴蝶

篮球弹弹弹

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值