0

My current code is working when location is found. But I want to make a check that if location is not found, it will redirect somewhere else.

Here is my code:

<script type="text/javascript">
    var userAgent = window.navigator.userAgent;
    if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
        window.location = "theMYApp://"
    }
    else
    {

    }
</script>

I want to check if window.location = "theMYApp://" does not exist

Bijan
  • 6,011
  • 13
  • 64
  • 120
Saime1953
  • 13
  • 5

1 Answers1

-1

If you want to check whether window.location object is existed on a web browser, you do not check. window.location object is always existed.

If you want to check text of 'theMYApp://' in window.location object, you can use below codes.

if (window.location.indexOf('theMYApp://') > -1) {
    // theMYApp:// string is found in url
}
gilchris
  • 1,221
  • 17
  • 24
  • I ended up here with the same issue. Ex: I want to know if I can check whether an app is installed in a device before redirecting the website to the app. – Cleriston Nov 28 '18 at 09:19