After using anonymous functions, and then using window.onload, the functions in window.onload are no longer executed. Why?

after using anonymous functions, and then using window.onload, the functions in window.onload are no longer executed. Why?

(function() {
    var hm = document.createElement("script");
    console.log(" == ", document.body.clientWidth);
})();
window.onload = function() {
    console.log(" == ", document.body.clientWidth);
}
Apr.21,2022

too little information, your code is correct


onload will not be executed until all the resources on the page have been loaded, and both console should be executed.


did you use ie to make a mistake.

Menu