Skip to content Skip to sidebar Skip to footer

Click Event Listener Works In Safari In Osx But Not In Ios

I'm making a web app and I want to click on an element and handle the click in one long click event handler. I'm testing in Safari. The following works fine in Safari on my Mac but

Solution 1:

This code should work cross-browser:

function Subscribe(event, element, func) {
    if (element.addEventListener) {
        element.addEventListener(event, func, false);
    } elseif (element.attachEvent) {
        element.attachEvent("on" + event, func);
    } else {
        element['on' + event] = func;
    }
}

function func () {
    alert('hi');
}

Subscribe('click', window, func);

Solution 2:

Try changing the event listener "click" to "click touchstart"

Solution 3:

I found a very simple solution. I put another div about the div element in my sample code (see my question above). The opening div tag is

<divonClick="">

All divs inside this div tag will now trigger the click event. This also works with touchstart.

Solution 4:

In my case I just needed to replace window to document:

Doesn't work on iOS:

window.addEventListener('click', () => {})

iOS compatible:

document.addEventListener('click', () => {})`

Post a Comment for "Click Event Listener Works In Safari In Osx But Not In Ios"