By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,207 Members | 1,065 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,207 IT Pros & Developers. It's quick & easy.

Javascript, Embedded Objects, and Unload Event

P: n/a
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?

Jan 4 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Owen.Leibman wrote:
<snip>
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?
It looks like you are seeing the 'in-memory' caching of previously
viewed web pages. That is generally a good idea as it allows for the
back button to operate very quickly. However, if the page includes an
onuload handler (frequently necessitated by IE's memory leak problems),
and that handler is executed when the page is navigated away from, then
the page in memory will be in an 'unloaded' state that will not
necessarily be appropriate for re-display as it is. So a reasonable
strategy would be to only store a page in memory for re-disarray on the
use of the back button if it did not have an onuload (and probably
onload) handler, and when the page did have such handlers it would make
more sense to re-load the page (from the browser's cache or from the
network) so that it could go into its loaded state as it normally would.

Richard.
Jan 4 '07 #2

P: n/a
Thanks. It seems a bit unexpected, but I think that explanation helps.

Richard Cornford wrote:
Owen.Leibman wrote:
<snip>
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?

It looks like you are seeing the 'in-memory' caching of previously
viewed web pages. That is generally a good idea as it allows for the
back button to operate very quickly. However, if the page includes an
onuload handler (frequently necessitated by IE's memory leak problems),
and that handler is executed when the page is navigated away from, then
the page in memory will be in an 'unloaded' state that will not
necessarily be appropriate for re-display as it is. So a reasonable
strategy would be to only store a page in memory for re-disarray on the
use of the back button if it did not have an onuload (and probably
onload) handler, and when the page did have such handlers it would make
more sense to re-load the page (from the browser's cache or from the
network) so that it could go into its loaded state as it normally would.

Richard.
Jan 5 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.