Search code examples
javascriptgwtjsni

JavaScript function changes does not appear in JSNI


I am changing JavaScript function in JSNI but eventlistener not call properly. Here is the code:

private native void alert1()/*-{
    $doc.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
        $wnd.alert("1111111");
    }, true);
}-*/;

Javascript function is :

document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) {
    window.alert("2222222222");
}, true);

any suggestions?


Solution

  • onModuleLoad is (almost) guaranteed to run after DOMContentLoaded, so:

    • you don't need to listen for that even in your code
    • if you do, it's too late and you event handler won't ever be called