get vibrate() to work in browser without PhoneGap

懵懂的女人 提交于 2019-12-01 20:26:01

问题


Does anybody know how to get something like navigator.vibrate() to work directly in the browser on a website (without using PhoneGap and the webview)? None of the commands found on http://www.w3.org/TR/vibration/ seem to work and all I could find are references to these commands working using PhoneGap. I have tried this fiddle here:

http://jsfiddle.net/robnyman/BrFvC/

but no joy! :-(

I am running Android 2.3, native browser, Firefox 10 and Maxthon 2.4.5 on an HTC Sensation XE. Does anybody know of a browser that supports this method (already)?


回答1:


Using Javascript:

navigator.vibrate(pattern);

example:

navigator.vibrate(250);

where 250 = 250 ms vibrate.

But - this is not fully supported across all browsers (Namely not by Safari). Check Browser Support for Reference: http://caniuse.com/#feat=vibration




回答2:


It depends on the browser, currently I've only found firefox mobile beta to support the vibrate API. You can find an example showing how this works here.

Basically you just have to make the following call:

navigator.mozVibrate(toPlay);


来源:https://stackoverflow.com/questions/9266285/get-vibrate-to-work-in-browser-without-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!