gpt4 book ai didi

JavaScript 浏览器代理重定向

转载 作者:行者123 更新时间:2023-11-30 18:33:24 24 4
gpt4 key购买 nike

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

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

是否有一种简单的方法来“反转”此代码,以便从任何其他浏览器登陆 iPhone 页面的任何人都将被重定向回主页?

非常感谢。

最佳答案

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

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

已更新,因为它仅适用于 iPhone 页面。

关于JavaScript 浏览器代理重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8960857/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com