1

Is there a way to fire a javascript function after everything on the page has loaded, after the back button has been used?

Basically I have search results which I store with localStorage which works great but I can't get the function to fire after everything else has loaded. It does fire but get overwritten by another function so want to wait until everything has finished.

I've tried:

window.onload
document.onload

if(window.attachEvent) {
    window.attachEvent('onload', yourFunctionName);
} else {
    if(window.onload) {
    var curronload = window.onload;
    var newonload = function() {
        curronload();
        yourFunctionName();
    };
    window.onload = newonload;
} else {
    window.onload = yourFunctionName;
    }
}

document.onreadystatechange = function () {
  if (document.readyState == "complete") {
    myFunction();
  }
}

Is there an absolute way after hitting the back button, knowing when the page has absolutely finished loading?

I'm using javascript, not jQuery

StudioTime
  • 22,603
  • 38
  • 120
  • 207
  • possible duplicate of [Cross-browser onload event and the Back button](http://stackoverflow.com/questions/158319/cross-browser-onload-event-and-the-back-button) – PlantTheIdea Aug 29 '14 at 15:36
  • I did see this but browsers change A LOT over 6 years and what's suggested on that post are hacks really. – StudioTime Aug 29 '14 at 15:47
  • agreed ... but if you are defining "absolute way" as "standards-complaint and universal" ... then there is no absolute way. the unload event hijack may be not be standardized, but then neither is `target="_blank"` and its used everywhere. gotta do what ya gotta do. – PlantTheIdea Aug 29 '14 at 19:35

0 Answers0