Make iphone/smartphone vibrate from website, is it possible?
Asked Answered
C

2

5

So im buiding a little quiz game using php, jQuery etc. I have maded it so each player uses his or hers smartphone as a "buzzer" button. And the i was wondering if it is possible to make the phone vibrate to give the user a nicer feedback of pressen the button.

I found a vibrate API but iOS is not supporting it (i have an iphone to test it)

It is the only thing i could found about it, someone know something else?

Conversable answered 10/11, 2014 at 8:24 Comment(0)
B
4

You can always use Phonegap/Cordova to pack the web content into a native app. Then you'll have access to all (or most) of the native phone features.

Bear in mind that using JS for vibration is still widely unsupported while the native thing will work on everything.

Bloodstone answered 10/11, 2014 at 8:26 Comment(2)
You are right, but it is really only ment to be a little game for and my friends and dont want to pay the cost of getting an app on appstore googlemarket etc. for just a little private thing :)Conversable
Yeah, I totally understand. But I'm not sure you have another choice, at least for now. Btw. you don't have to publish the app in order to use it on the phone (it's super-simple on Androids, a bit more difficult on iPhones).Bloodstone
A
4

Yes it is, using HTML5's Vibration API. To make the phone vibrate, use:

navigator.vibrate(1000);

However before executing this statement, you should check whether the browser supports the Vibration API. You can do this either this way:

if (window.navigator && window.navigator.vibrate) {
   // Vibration supported
} else {
   // Vibration not supported
}

Or this way:

if ('vibrate' in navigator) {
   // Vibration supported
} else {
   // Vibration not supported
}

You can also define a vibration pattern. This is possible by passing an array with [vibration, pause, vibration, pause...], like so:

// Vibrate for 3 seconds, pause for half a second, vibrate for 2 seconds, pause for half a second, vibrate for 1 second    
navigator.vibrate([3000, 500, 2000, 500, 1000]);

To make the phone stop vibrating, you can use either:

navigator.vibrate(0);

Or:

navigator.vibrate([]);

Source: tutplus

Archduke answered 12/7, 2015 at 21:34 Comment(1)
is there a way to vibrate in IOS ??Uncourtly

© 2022 - 2024 — McMap. All rights reserved.