简体   繁体   中英

window.onload() not working with html content generated by proprietary fwk

I am using a mobile application development framework ADF Mobile whereby we could develop cross-platform mobile applications.UI layer can be developed with a set of components (AMX) that generate an HTML5 based user interface and whose DOM structure can be debugged with iOS simulator+ Safari browser builtin debugger. Also ADF Mobile internally uses Cordova

I need to have a javascript called when the page completes loading. I tried various approaches like

$(document).ready(function () {
    console.log("just inside the  $(document).ready()");
});

window.onload = function () {
    //handler function
};

/*
$(window).load(function () {
    //handler function
});
$(window).bind('load', function () {
    //handler function
});

window.addEventListener("load", handlerFunction);
*/

Everything related to 'load' event fails but 'ready' event is getting fired as expected. Once a handler function is associated to the "load" event, when we inspect the window object of the html using the safari dom debugger, the onload attribute has the handler function we are assigning but the only issue is that it is not getting fired when the page is completely loaded.

Can I get any starters on debugging this issue? Or any pointers in getting workarounds will also do.

I was more interested in knowing how this entire mechanism works.

How about this ,

$(window).on('unload', function(){
      return 'Are you sure you want to leave?';
});

Actually some browsers such as Google Chrome might block if you attempt to alert in a window unload.

Replace the alert with a console.log or something else less intrusive to the user and the event will be happily called.

Hope this helps you.....

尝试从Javascript调试器控制台执行window.location.reload()。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM