Export to GitHub

reallysimplehistory - issue #3

RSH clobbers window.onunload


Posted on Oct 2, 2007 by Massive Elephant

What steps will reproduce the problem? 1. Add dhtmlHistory.js to a page that already has an onunload handler, like this: <script type="text/javascript"> window.onunload = function() { alert("my unload handler"); } </script> <script type="text/javascript" src="dhtmlHistory.js"></script> 2. Note that the onunload handler you added doesn't get run.

What is the expected output? What do you see instead?

I expect the library to run the existing onunload handler before doing the onunload cleanup that it needs to do. Instead, the onunload handler is clobbered.

What version of the product are you using? On what operating system?

.04 on all browsers.

Please provide any additional information below.

I believe the following patch will work. Replace these lines:

  var self = this;
  window.onunload = function() {
     self.firstLoad = null;
  };

with these lines:

  var self = this;
  var previousOnUnload = window.onunload;
  window.onunload = function() {
     self.firstLoad = null;
     if (previousOnUnload) previousOnUnload();
  };

Comment #1

Posted on Oct 2, 2007 by Massive Elephant

Sorry, meant to say "I expect the library to run the existing onunload handler AFTER doing the onunload cleanup that it needs to do."

Comment #2

Posted on Oct 28, 2007 by Happy Lion

Comment deleted

Comment #3

Posted on Oct 31, 2007 by Happy Lion

Comment deleted

Comment #4

Posted on Nov 5, 2007 by Happy Lion

Comment deleted

Comment #5

Posted on Nov 7, 2007 by Happy Lion

Xander, thanks for the suggested patch. I ended up fixing this with a fairly standard cross-browser event registration method. There's no way to guarantee execution order of unload events registered this way, but I don't think it should matter. I can't imagine a scenario where somebody would be relying on a non-null value for dhtmlHistory.firstLoad during their own custom unload events.

Status: Fixed

Labels:
Type-Defect Priority-Critical