2015-05-19 24 views
0

我的當前代碼在找到位置時正在工作。但是我想檢查一下,如果沒有找到位置,它會重定向到別的地方。如何檢查window.location是否存在

這裏是我的代碼:

<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的對象是否存在於網絡瀏覽器來檢查,如果window.location = "theMYApp://"不存在

回答

0

,你做不檢查。 window.location對象始終存在。

如果你想檢查window.location對象中'theMYApp://'的文本,你可以使用下面的代碼。

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