I have this code to redirect users to the mobile UI. First it will check if it's a mobile second it will check if there is a cookie, and third is to check the URL if NOT contains these words ("DispForm,NewForm,EditForm"). But just doesn't
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";
}
}
}
Can someone tell me why please?
it's checking if there is not a cookie:
if (document.cookie.indexOf("DesktopView=") < 0) {...}
If you want to check if there is a cookie it should be:
if (document.cookie.indexOf("DesktopView=") >= 0) {...}
You are checking to see if the URL "doesn't contain NewForm" OR "doesn't contain DispForm" etc.
You probably mean &&
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.