2

I am having to use multiple window.onload functions on one page because the JS plugin that I am using is calling the window.onload function already. I would like to not edit the plugin and work around it. Here is what I have tried:

<div id="Count"></div>

//<script type="text/javascript" src="plugin.js" /> // JS plugin using window.onload

var INCREMENT = 3;
var count = 0;
var msInterval = 800;
var oldonload = window.onload; // assigning current window.onload to a variable

window.onload = function() { <-- error line
  if (oldonload) {
    oldonload();
  }
  document.getElementById('Count').innerHTML = count;
  setInterval("count += INCREMENT; document.getElementById('Count').innerHTML = count;", msInterval);
}

I am getting this error:

TypeError: (intermediate value)(...) is not a function

user4756836
  • 1,277
  • 4
  • 20
  • 47

1 Answers1

5

Try using addEventListener instead.

function myFunction() {
    // do stuff here
}
window.addEventListener("load", myFunction, false);
Andrew Jenkins
  • 1,590
  • 13
  • 16