当用户允许或拒绝访问“物理位置”时如何调用功能? [英] How to call function when user Allows or Denies access to "Physical Location"?
问题描述
我的应用程序试图获取用户的位置后,(Chrome)浏览器会提示用户:
p>
Example.com希望追踪您的实际位置[允许] [拒绝]
我的目标是:
- 如果用户点击允许,则调用函数1(使用位置
by app)。 - 如果用户点击Deny,则调用函数2(地址表单
出现)。
当用户点击Allow或Deny按钮时,如何将函数绑定到发生的事件(如果有)?$ b $ getCurrentPosition
函数接受两个函数参数。哎呀,第一个是你允许的时候执行的,第二个是你拒绝的时候执行的!
http://jsfiddle.net/ pimvdb / QbRHg /
navigator.geolocation.getCurrentPosition(function(position){
alert('允许');
},函数(){
alert('deny');
});
My application is powered by jquery mobile and uses geolocation.
After my application attempts to get the user's location, the (Chrome) browser prompts the user:
Example.com wants to track your physical location [allow] [deny]
My goal is:
- If the user clicks "Allow", function 1 is called (location is used by app).
- If the user clicks "Deny", function 2 is called (address form appears).
How can I bind a function to the event that occurs (if any) when the user clicks the "Allow" or "Deny" button?
The getCurrentPosition
function accepts two function arguments. Heck, the first is executed when you allow and the other when you deny!
http://jsfiddle.net/pimvdb/QbRHg/
navigator.geolocation.getCurrentPosition(function(position) {
alert('allow');
}, function() {
alert('deny');
});
这篇关于当用户允许或拒绝访问“物理位置”时如何调用功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!