JavaScript浏览器代理重定向

JavaScript浏览器代理重定向,javascript,iphone,browser,agent,Javascript,Iphone,Browser,Agent,如果用户使用iPhone,我的网页标题中有一段代码可以将用户重定向到不同的页面: <script type="text/javascript"> if ((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1)) { document.location = "iPhone.aspx"; } </script> if((navigato

如果用户使用iPhone,我的网页标题中有一段代码可以将用户重定向到不同的页面:

<script type="text/javascript">
if ((navigator.userAgent.indexOf('iPhone') != -1) ||  
(navigator.userAgent.indexOf('iPod') != -1)) {  
document.location = "iPhone.aspx"; }
</script>

if((navigator.userAgent.indexOf('iPhone')!=-1)|
(navigator.userAgent.indexOf('iPod')!=-1)){
document.location=“iPhone.aspx”;}
有没有一种简单的方法来“反转”这个代码,这样任何从其他浏览器登陆iPhone页面的人都会被重定向回主页


非常感谢

要反转吗?更换
!=-1带有
==-1

编辑:

假设你的意思是这样的:

if ((navigator.userAgent.indexOf('iPhone') != -1) ||  
(navigator.userAgent.indexOf('iPod') != -1)) {  
document.location = "iPhone.aspx"; } else {
document.location = "notiPhone.aspx";
}
(navigator.userAgent.indexOf('iPhone')==-1
表示userAgent中没有这样的字符串“iPhone”。因此,当您从
!=
更改为
=
时,您还需要将
|
更改为
&

if ((navigator.userAgent.indexOf('iPhone') == -1) 
   && (navigator.userAgent.indexOf('iPod') == -1)) {  
    document.location = 'default.aspx';
}

简单的解决方案。用此解决方案替换现有的解决方案

if(!/(iphone|ipod)/i.test(navigator.userAgent)) {
   window.location = "Desktop.aspx";
}

更新,因为它只针对iPhone页面。

我尝试了:if((navigator.userAgent.indexOf('iPhone')=-1)| |(navigator.userAgent.indexOf('iPod')=-1)){document.location=“Default.aspx”;)但是,它只是在循环中发送iPhone,从Default.aspx跳转到iPhone.aspxy。您应该记录或提醒userAgent字符串,并查看字符串是否匹配。此外,请尝试提醒(navigator.userAgent.indexOf('iPhone')—出现了什么情况?