最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get vibrate() to work in browser without PhoneGap - Stack Overflow

programmeradmin5浏览0评论

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 mands found on / seem to work and all I could find are references to these mands working using PhoneGap. I have tried this fiddle here:

/

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)?

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 mands found on http://www.w3/TR/vibration/ seem to work and all I could find are references to these mands working using PhoneGap. I have tried this fiddle here:

http://jsfiddle/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)?

Share Improve this question edited Nov 11, 2013 at 23:37 BenMorel 36.7k52 gold badges206 silver badges337 bronze badges asked Feb 13, 2012 at 19:00 user1207504user1207504 3673 silver badges11 bronze badges 3
  • PhoneGap is just a wrapping layer, download the source and steal what you need. – Karl-Bjørnar Øie Commented Feb 13, 2012 at 19:04
  • 5 You can't. That's the whole point of PhoneGap: to bridge the gap between what you can do from a pure web application and what you can do with a native application. Someday the device manufacturers may provide more APIs for JavaScript in web pages, but there's a lot of incentive for them not to do so. – Pointy Commented Feb 13, 2012 at 19:06
  • Thanks for your help guys. I will give ZeroPage's suggestion a go and let you know once I got some results, but Pointy makes a really good point (pun not intended) re PhoneGaps' actual purpsose and the problem with the manufacturers' feature support. Let's hope I can dig up sth. Cheers. – user1207504 Commented Feb 15, 2012 at 8:57
Add a ment  | 

2 Answers 2

Reset to default 3

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./#feat=vibration

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);
发布评论

评论列表(0)

  1. 暂无评论