Recipe 14.6

Making the Device Vibrate

The navigator.vibrate method, on supported devices, lets you make the device vibrate to call attention to the user.

You can trigger a single vibration, or a sequence of vibrations and pauses.

Code

JavaScript
// A single vibration for 500ms
navigator.vibrate(500);

// A pattern of multiple vibrations
// Vibrate for 500ms three times, with a 250ms pause in between
navigator.vibrate([500, 250, 500, 250, 500]);

Web API Cookbook
Joe Attardi