我正在构建一个使用Geolocation API的应用程序.我似乎无法在Firefox 10上使用一段非常简单的代码.以下是代码:
window.onload = function() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
alert('it works');
}, function(error) {
alert('Error occurred. Error code: ' + error.code);
});
}else{
alert('no geolocation support');
}
};
Run Code Online (Sandbox Code Playgroud)
因此,例如,在Chrome中,在运行页面后,系统会询问我是否要共享我的位置,点击"是"后会提醒我"它有效".现在在Firefox 10中,它会让我分享我的位置,点击分享后它什么也没做......我一直试图让回调运行任何类型的代码,但没有运气.这是Firefox的错误还是我做错了什么?我在这里有一个代码测试示例:http://dev-hub.com/geolocation.html.
编辑---我的操作系统是Windows 7 64位
好的,我刚刚意识到PHP的一些奇怪的行为,并想知道为什么会发生这种情况.所以运行这段代码:
var_dump( true and false ? 'one' : 'two' );
Run Code Online (Sandbox Code Playgroud)
输出
boolean true
Run Code Online (Sandbox Code Playgroud)
而不是你想象中的'两个'......问题似乎是使用'和'.
运行:
var_dump( true && false ? 'one' : 'two' );
Run Code Online (Sandbox Code Playgroud)
输出
string 'two' (length=3)
Run Code Online (Sandbox Code Playgroud)
正如预期的那样.为什么使用'和'代替'&&'导致这种奇怪的行为?他们不应该是一样的吗?
所以基本上我有这样的东西
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<div class="iframe-holder">
<span></span>
<iframe src="iframe.html" width="200" height="200"
</div>
<script>
function where_am_i(iframe_parent_div,msg){
$(iframe_parent_div).find('span').html(msg);
}
</script>
Run Code Online (Sandbox Code Playgroud)
然后在我的iframe-holder.html我基本上有这个
<a href="#" id="msg">Show Message In Parent Div</a>
<script>
//i want to basically imp
$('msg').click(function(event){
event.preventDefault();
var iframe_parent_div=???;//how do I get this?
parent.where_am_i(iframe_parent_div,'This is where this iframe is');
});
</script>
Run Code Online (Sandbox Code Playgroud)
所以基本上我的问题是如何定位iframe实例的父div(div.iframe-holder)我点击"显示消息"按钮?这甚至可能吗?
我知道我可以通过源发送一个带索引的变量if iframe.html?index = 0表示第一个iframe.html?index = 1表示第二个等等但是这对我来说不是一个可行的解决方案,因为在iframe会有很多导航到不同的页面,所以传递到所有页面索引不是一个选项.