如何检查window.location是否存在
问题描述:
我的当前代码在找到位置时正在工作。但是我想检查一下,如果没有找到位置,它会重定向到别的地方。如何检查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://"
不存在
答
,你做不检查。 window.location对象始终存在。
如果你想检查window.location对象中'theMYApp://'的文本,你可以使用下面的代码。
if (window.location.indexOf('theMYApp://') > -1) {
// theMYApp:// string is found in url
}