0

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?

2 Answers 2

1

You are checking to see if the URL "doesn't contain NewForm" OR "doesn't contain DispForm" etc.

You probably mean &&.

Sign up to request clarification or add additional context in comments.

Comments

1

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) {...}

1 Comment

Yes correct and it works find. The problem is with the there If statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.