2013-10-14 69 views
0

我曾作过的网站的移动版本(在其他文件夹与第二的index.html)如何移动网站重定向到正常的版本

我用这个脚本从桌面版的移动重定向手机版

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; 
}  

工作的很好,但问题是,共享移动版本的人发送人移动,由于移动网址。所以,我试图把它们自动重定向到桌面版类似这样的

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; 
} 

,关于iphone的工作,但创建与iPad无限循环,我该怎么办吗? 我只能用JavaScript来做到这一点

我不能使用脚本一样,因为iPad的视网膜和其他决议

回答

0

这也将导致iPod的无限循环的 if (screen.width <= 960) {document.location = mobile.html";} 。在你的第二个剧本中你应该是缺少的!

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; 
} 

,你也需要改变||'s到& &的,因为如果没有他们(的iPod,iPad的,iPhone)匹配它应该重定向。

+0

哦,来自我的愚蠢的错误,谢谢! – kaiz3r

相关问题