当用户允许或拒绝访问“物理位置”时如何调用功能? [英] How to call function when user Allows or Denies access to "Physical Location"?

查看:104
本文介绍了当用户允许或拒绝访问“物理位置”时如何调用功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的应用程序试图获取用户的位置后,(Chrome)浏览器会提示用户:

p>


Example.com希望追踪您的实际位置[允许] [拒绝]


我的目标是:


  1. 如果用户点击允许,则调用函数1(使用位置
    by app)。

  2. 如果用户点击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:

  1. If the user clicks "Allow", function 1 is called (location is used by app).
  2. 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!

Documentation

http://jsfiddle.net/pimvdb/QbRHg/

navigator.geolocation.getCurrentPosition(function(position) {
    alert('allow');
}, function() {
    alert('deny');
});

这篇关于当用户允许或拒绝访问“物理位置”时如何调用功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆