Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigator vibrate break the code on ios browsers

I want to use navigator.vibrate on my page.

This is my code:

    var canVibrate = "vibrate" in navigator || "mozVibrate" in navigator;
    if (canVibrate && !("vibrate" in navigator))
    {
        navigator.vibrate = navigator.mozVibrate;
    }

    $(document).on('click', '.answer', function (eve) {
        $this = $(this);

        navigator.vibrate(222);

        // some other code ...

This works on Android devices but on iOS (I tested on Firfox, Chrome and Safari on some iOS devices) the code will be broken at this line.

Why is that?

like image 970
Kiyarash Avatar asked Jul 07 '19 22:07

Kiyarash


People also ask

How do I get IOS notifications to vibrate?

Go to Settings > Sounds & Haptics or Settings > Sounds. Select an option under Sounds and Vibration Patterns. Tap Vibration, then tap Create New Vibration.

What is navigator vibrate?

The Navigator. vibrate() method pulses the vibration hardware on the device, if such hardware exists. If the device doesn't support vibration, this method has no effect. If a vibration pattern is already in progress when this method is called, the previous pattern is halted and the new one begins instead.


1 Answers

Apple's mobile web browser simply does not have support for it.

Firefox and Chrome for iOS are wrappers around Safari's rendering engine.

like image 85
Quentin Avatar answered Oct 04 '22 14:10

Quentin