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 not in iOS:
<html>
<head>
<script>
window.addEventListener("click",function (event) {
alert('hi');
});
</script>
</head>
<body>
<div style="width: 100%; height: 100%; background: black;">
</div>
</body>
</html>
Why does this work in the OSX version of Safari but not in iOS?
This code should work cross-browser:
function Subscribe(event, element, func) {
if (element.addEventListener) {
element.addEventListener(event, func, false);
} else if (element.attachEvent) {
element.attachEvent("on" + event, func);
} else {
element['on' + event] = func;
}
}
function func () {
alert('hi');
}
Subscribe('click', window, func);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With