JavaScript 浏览器代理重定向
我的网页标题上有一小段代码,用于将用户重定向到不同的页面(如果他们使用 iPhone):
<script type="text/javascript">
if ((navigator.userAgent.indexOf('iPhone') != -1) ||
(navigator.userAgent.indexOf('iPod') != -1)) {
document.location = "iPhone.aspx"; }
</script>
是否有一种简单的方法来“反转”此代码,以便任何人从任何其他页面登陆 iPhone 页面浏览器会被重定向回主页吗?
非常感谢。
I've got this little bit of code on my webpage header to redirect the user to a different page if they are using an iPhone:
<script type="text/javascript">
if ((navigator.userAgent.indexOf('iPhone') != -1) ||
(navigator.userAgent.indexOf('iPod') != -1)) {
document.location = "iPhone.aspx"; }
</script>
Is there an easy way to 'reverse' this code, so anyone landing on the iPhone page from ANY other browser will be redirected back to the home page?
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简单的解决方案。用这个替换你现有的。
已更新,因为它仅适用于 iPhone 页面。
Simple solution. Replace your existing one with this.
Updated since its only for iPhone page.
要扭转?将
!= -1
替换为== -1
编辑:
假设您的意思是这样的:
To reverse? Replace
!= -1
with== -1
Edit:
Suppose you mean something like this:
(navigator.userAgent.indexOf('iPhone') == -1
表示 userAgent 中没有这样的字符串“iPhone”。因此,当您从!=
更改为==
,您还需要将||
更改为&&
。(navigator.userAgent.indexOf('iPhone') == -1
means there is no such string "iPhone" in the userAgent. So when you change from!=
to==
, you need to change||
to&&
as well.