[英]how to redirect mobile website to normal version
i actually made a website with a mobile version (in an other folder with a second index.html) 我实际上制作了一个带有移动版本的网站(位于另一个文件夹中,带有第二个index.html)
i've used this script to redirect mobile from desktop version to the mobile version 我已经使用此脚本将移动设备从桌面版本重定向到移动版本
if ( navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) ){
window.location.href = "http://m.website.net" + document.location.hash;
}
that work well but the problem is that people who share the mobile version send people to mobile, due to mobile url. 效果很好,但问题是由于使用移动网址,共享移动版本的用户将人们转移到了移动设备上。 So i try to redirect them automatically to the desktop version like this 所以我尝试将它们自动重定向到这样的桌面版本
if (! navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i) ){
window.location.href = "http://www.website.net" + document.location.hash;
}
that worked on iphone but create an infinite loop with ipad, how can i do please ? 可以在iphone上使用,但是使用ipad可以创建无限循环,我该怎么办? i can only use javascript to do this 我只能使用javascript来做到这一点
i can't use script like if (screen.width <= 960) {document.location = mobile.html";}
because of ipad retina and other resolutions 由于ipad视网膜和其他分辨率,我无法使用if (screen.width <= 960) {document.location = mobile.html";}
类的脚本
That will also cause infinite loop in iPods. 这也将导致iPod中的无限循环。 You are missing !'s in your second script it should be. 您应该在第二个脚本中缺少!。
if (!navigator.userAgent.match(/iPhone/i) && !navigator.userAgent.match(/iPod/i) && !navigator.userAgent.match(/iPad/i) ){
window.location.href = "http://www.website.net" + document.location.hash;
}
you also need to change ||'s to &&'s since it should redirect if none of them(iPod,iPad,iPhone) matches. 您还需要将||更改为&&,因为如果它们(iPod,iPad,iPhone)都不匹配,则应该重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.