Core JavaScript

Vibrate a Phone

This program demonstrates how to vibrate a phone in JavaScript.

Vibrate.html

<!DOCTYPE html>
<html>
	<head>
		<title>XoaX.net's Javascript</title>
	</head>
	<body>
		<div style="width:300px;">
			<fieldset>
    		<legend>Vibration</legend>
				<button id="idVibrate">Vibrate</button>
			</fieldset>
		</div>
		<script type="text/javascript">
			const qVibrateButton = document.getElementById('idVibrate');

			qVibrateButton.addEventListener('click', () =>{
				if ('vibrate' in navigator) {
					navigator.vibrate([300, 100, 200, 200, 400, 100]);
				} else {
					alert('Vibration not available');
				}
			});
		</script>
	</body>
</html>
 

Output

 
 

© 2007–2025 XoaX.net LLC. All rights reserved.