I'm developing a mobile web app and noticed that custom Javascript events are not working on my iPad with iOS 5. Same model iPad with iOS 6 works flawlessly, and current Safari also handles the code correctly. Here's my test:
yoo = function (event) {
alert("event received!");
}
window.addEventListener("go", yoo);
var event = new Event("go");
window.dispatchEvent(event);
I tried to work around this by using jQuery binding/triggering functions--- that didn't work either.
Any hints? Am I missing something basic that I need to do when binding and dispatching custom events on iOS 5's webkit?
You're missing third parameter, could that cause the error behavior on iOS5? Also initEvent could be used:
window.addEventListener("go", yoo, false);
var evt = document.createEvent('Event');
evt.initEvent("go", true, true);
window.dispatchEvent(evt);