I fire my javascript using the onload property -> window.onload = function(){ // start code }
Rececently I started doing an .innerHTML write to the <head> tag which sets my .js file.
document.head.innerHTML = html_string
// where html_string contains the link to my .js file.
Problem I’m having is that now the onload function is never called so my page has no javascript on it.
Is there a way to manually call it or emulate its behavior?
Don’t insert the scripts by setting the
innerHTMLofdocument.head. Add a<script>DOM node and listen for its load event: https://stackoverflow.com/a/9102718/1048572, Capturing onload event when dynamically loading .js files?, jQuery event that triggers after CSS is loaded?