--- title: Window.ondeviceproximity slug: Web/API/Window/ondeviceproximity translation_of: Web/API/Window/ondeviceproximity ---

{{ ApiRef() }}

指定一个事件监听器来接受 {{event("deviceproximity")}} 事件,当设备传感器检测到一个对象越来越接近或远离设备时这些事件就会出现。

语法

window.onuserproximity = funcRef

其中funcRef是在发生 {{event("deviceproximity")}} 事件时要调用的函数。这些事件的类型为{{domxref("DeviceProximityEvent")}}。

规范

Specification Status Comment
{{ SpecName('Proximity Events', '#device-proximity', 'Proximity Events') }} {{ Spec2('Proximity Events') }} Initial specification

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatNo() }} {{ CompatVersionUnknown() }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatNo() }} {{ CompatNo() }} {{ CompatGeckoMobile("15.0") }} {{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

See also