Why is windows.onload executed several times?

I am binding a window.onload event like this

// It a little more complex than this, I analyze if there is any other function 
// attached but for the sake of the question it ok, this behaves the same.
window.onload = myfunction; 

Onload runs twice on my local computer several times on the production server

If I changed it to jQuery equivalent

$jQuery(window).load(myfunction);

It behaves as expected (performed only once).

Could you help me understand the possible reasons why the first option does not work as intended?

Thank!

+3
source share
1 answer

myfunction() — . , myfunction, , window.onload, . , , , , , return this;

window.onload = myfunction;

a >


window.onload, , myfunction. , . Chrome.

:

var alertme = function() {
    alert("Hello");
}

window.onload = alertme;

function testsecondcall() {
    alertme();
}

testsecondcall();
  • Chrome.
  • , , " " , .
  • , . ( window.onload). :

enter image description here

, " " , alertme testsecondcall

+6

All Articles