让vibrate()在没有PhoneGap的浏览器中工作 [英] get vibrate() to work in browser without PhoneGap
问题描述
有人知道如何使用navigator.vibrate()直接在网站上的浏览器中工作(不使用PhoneGap和webview)吗? http://www.w3.org/TR/vibration/ 上找不到任何命令似乎工作,我所能找到的是使用PhoneGap工作的这些命令的引用。我在这里试过这个小提琴:
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! :-(
我正在运行
Android 2.3,原生浏览器,Firefox 10和Maxthon 2.4 .5在HTC Sensation XE上。
有没有人知道支持这种方法的浏览器(已经)?
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)?
推荐答案
使用Javascript:
Using Javascript:
navigator.vibrate(pattern);
示例:
navigator.vibrate(250);
其中250 = 250毫秒振动。
where 250 = 250 ms vibrate.
但是 - 并非所有浏览器都支持此功能(即Safari不支持)。查看浏览器支持以供参考: http:// caniuse .com /#feat =振动
But - this is not fully supported across all browsers (Namely not by Safari). Check Browser Support for Reference: http://caniuse.com/#feat=vibration
这篇关于让vibrate()在没有PhoneGap的浏览器中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!