Here is a complete web page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>Javascript Embed and onunload</title>
<script type="text/javascript">
function useplayer() {
var a = document.getElementById("obj1");
var obj = document.createElement("object");
obj.data = "dayenu.mid";
obj.type = "audio/x-midi";
obj.height = 60;
obj.width = 120;
a.parentNode.replaceChild(obj,a);
}
function donothing() {}
/* if (window.addEventListener)
addEventListener("unload",donothing,false); */
</script>
</head>
<body>
<div id="div1">
<a href="unload3.html">Navigate from page</a><br>
<a id="obj1" href="javascript:useplayer();">Use Embedded Object</a>
</div>
</body>
</html>
I have copies of it at http://www.dayenu.com/test2/unload1.html (with
the addEventListener line commented out), and
http://www.dayenu.com/test2/unload2.html (with the addEventListener
line uncommented). The one commented line is the only difference. Now
for my question.
If I bring up unload1.html in Firefox or Opera or Safari (this question
doesn't apply to IE) and click on the "Use Embedded Object" link, the
link will be replaced by an embedded object which plays my song. When I
click on "navigate from page", I get a new page; when I use the back
button, my object is still embedded and starts playing.
When I do the same thing with unload2.html, the first click acts the
same, and clicking on "navigate from page" acts the same. However, when
I use the back button now, the page to which I return shows the
original "use embedded object" link, not the embedded object. The only
difference between the 2 pages is that, at unload time for unload2, I
executed a function which does *nothing*. Can anyone tell me why this
causes such a difference in behavior?