HTMLify

js2.html
Views: 182 | Author: demo
<!DOCTYPE html>
<html>
<head>
    <title>Vibration Button</title>
</head>
<body>
    <button id="vibrateButton"><h1>Vibrate</h2></button>

    <script>
        // Function to trigger vibration
        function vibratePhone() {
            if ("vibrate" in navigator) {
                // Vibrate for 1000 milliseconds (1 second)
                navigator.vibrate(1000);
            } else {
                console.log("Vibration API not supported");
            }
        }

        // Attach the vibratePhone function to the button click event
        document.getElementById("vibrateButton").addEventListener("click", vibratePhone);
    </script>
</body>
</html>

Comments