Menu

#167 DynAPI steps on previously set events

open
nobody
5
2001-09-05
2001-09-05
Paul August
No

If you have previously set a window.onload or
window.onunload event, DynAPI destroys it. The
following coded added to dynapi.js fixes this by
saving any previously set load and unload routines and
executing them as part of its load and unload.

DynAPIOtherOnLoad = (window.onload) ? window.onload :
new Function;
onload = function() { DynAPI.loadHandler();
DynAPIOtherOnLoad();}
//onload = function() { DynAPI.loadHandler(); }

DynAPIOtherOnUnLoad = (window.onload) ?
window.onload : new Function;
onunload = function() { DynAPI.unloadHandler();
DynAPIOtherOnUnLoad(); }
//onunload = function() { DynAPI.unloadHandler(); }

Play nicely in the sandbox with others... :)

Paul

Example: when you load the page without DynAPI you get
the alert. When you load DynAPI AFTER setting the
onload event, it is bypassed. With the above fix, it
once again gets executed.

<HTML>
<SCRIPT Language="JavaScript">
function myOnLoad() {
alert("in myOnLoad");
}
window.onload = myOnLoad;
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript"
SRC="/dynapi/src/dynapi.js"></SCRIPT>
<BODY>
</BODY>
</HTML>

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.