如何检查窗口.位置是否存在


How to check window.location exist or not

找到位置时,我当前的代码正在工作。但是我想做一个检查,如果没有找到位置,它将重定向到其他地方。

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

我想检查window.location = "theMYApp://"是否不存在

如果要检查窗口。web浏览器上存在Location 对象,您没有检查。窗口。Location 对象总是存在的。

如果你想检查窗口中'theMYApp://'的文本。对象,您可以使用以下代码:

if (window.location.indexOf('theMYApp://') > -1) {
    // theMYApp:// string is found in url
}