[英]Why this If statement with OR operation doesn't work in JavaScript?
我有这段代码将用户重定向到移动UI。 首先,它将检查它是否是移动设备;其次将检查是否有cookie;第三是检查URL,如果其中不包含这些单词(“ DispForm,NewForm,EditForm”)。 但是只是不
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
if (document.cookie.indexOf("DesktopView=") < 0) {
if (document.location.href.indexOf('NewForm') === -1 || document.location.href.indexOf('DispForm') === -1 || document.location.href.indexOf('EditForm') === -1) {
document.location = "/_layouts/Mobile/index.aspx";
}
}
}
有人可以告诉我为什么吗?
它正在检查是否没有 cookie:
if (document.cookie.indexOf("DesktopView=") < 0) {...}
如果要检查是否有cookie,应为:
if (document.cookie.indexOf("DesktopView=") >= 0) {...}
您正在检查URL是否“不包含NewForm”或“不包含DispForm”等。
您可能是说&&
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.