判断是电脑端还是手机短的javascript,自动跳转到手机wap版网站

2025-04-30 03:54:11
推荐回答(2个)
回答1:

主要在在于判断浏览器类型的部分
你上面已经写了“各种判断手机浏览器类型的代码”,同理
function ispc()//定义了一个判断主流pc浏览器,不全
{
var re=false;
if(navigator.userAgent.indexOf("MSIE")>0) {
re=true
}
if(navigator.userAgent.indexOf("Firefox")>0){
re=true }
if(navigator.userAgent.indexOf("Opera")>0){
re=true }
if(navigator.userAgent.indexOf("Camino")>0){
re=true }
if(navigator.userAgent.indexOf("Gecko")>0){
re=true }
return re;
}

具体执行判断代码就是 if(ispc()){
window.location.href='pc网站地址'

}

回答2:

navigator.userAgent