Javascript iPhone选择
快速提问。我正在写一个网站,希望根据用户的浏览器和iPhone操作软件的版本,将用户重定向到不同的网页。我知道你可能会对我说,应该由用户决定他们浏览哪个网站,在这件事上他们没有选择的余地 我使用的代码是javascript,可以识别不同的浏览器,但不能识别iPhone操作系统,这是关键。代码如下:Javascript iPhone选择,javascript,iphone,Javascript,Iphone,快速提问。我正在写一个网站,希望根据用户的浏览器和iPhone操作软件的版本,将用户重定向到不同的网页。我知道你可能会对我说,应该由用户决定他们浏览哪个网站,在这件事上他们没有选择的余地 我使用的代码是javascript,可以识别不同的浏览器,但不能识别iPhone操作系统,这是关键。代码如下: if(navigator.userAgent.match(/iPhone/i)) { if(navigator.userAgent.match(Version/4)){ if
if(navigator.userAgent.match(/iPhone/i)) {
if(navigator.userAgent.match(Version/4)){
if(document.cookie.indexOf("iphone_redirect=false") == -1) window.location ="iPhone4.html";
}
if(document.cookie.indexOf("iphone_redirect=false") == -1) window.location ="iPhone.html";
}
//Rest of the site goes here
不确定括号是否在这里,现在还为时过早,可能是弄错了,但如果有任何帮助,我们将不胜感激
SamiPhone 4用户代理字符串的设置如下: Mozilla/5.0(iPhone;U;CPU iPhone OS 4_0,如Mac OS X;en-us)AppleWebKit/532.9(KHTML,如Gecko)版本/4.0.5 Mobile/8A293 Safari/6531.22.7 旧iPhone应该对您有所帮助: Mozilla/5.0(iPhone;U;CPU iPhone OS 3_0,如Mac OS X;en-us)AppleWebKit/528.18(KHTML,如Gecko)版本/4.0 Mobile/7A341 Safari/528.16 因此,在您的代码中,iphone4的版本为4.0.5,iPhone的版本为4.0。这应该可以:
if(navigator.userAgent.match(/iPhone/i)) {
if(navigator.userAgent.match(/iPhone OS 4/i)) {
if(document.cookie.indexOf("iphone_redirect=false") == -1) {
window.location ="iPhone4.html";
}
}
else {
if(document.cookie.indexOf("iphone_redirect=false") == -1) {
window.location ="iPhone.html";
}
}
}
感谢您的回复,代码的问题在于它在运行iOS4时无法选择正确的页面,这意味着第二个“if”语句没有正确解析,目前我有代码:'if(navigator.userAgent.match(/iPhone OS 4/I)){'这是为了检测iPhone是否运行iOS4。请注意发布您正在使用的完整代码,我没有看到原始问题中的这一部分,它将帮助您获得所需的信息。