Hi Kiffin,
I'd also like to hear any new ideas on this. The last time we discussed it the following was suggested.
In the following example I assume...
- the Head element is not in the included file.
- the page-specific onload function is named the same in each page. In this example - myOnload().
Code:
<html>
<head>
<!--#include virtual="/includes/header.htm"#-->
<script type="text/javascript">
function myOnload() {
...
}
</script>
</head>
<body>
...
</body>
</html>
At the end of the windowOnload function (in the included file), do something like this...
Code:
<script type="text/javascript">
function windowOnload() {
...
if (window.myOnload) myOnload();
}
</script>
And there could be variations of the above.
Actually I think the only problem is when the local onload handler is assigned in the opening Body tag. The following is an idea for 'cascading' the onload handlers.
The following is CBE's onload handler (in cbe_core.js):
Code:
window.onload = function() {
cbeInitialize("DIV", "SPAN");
if (window.windowOnload) window.windowOnload();
}
For my experiment I replaced the above with this:
Code:
window.originalOnload = window.onload;
window.onload = function() {
cbeInitialize();
if (window.windowOnload) window.windowOnload();
if (window.originalOnload) window.originalOnload();
}
It saves a reference to the current onload handler, so it can call it later during the onload event.
This works but it has one ugly requirement... if you are going to define your own window.onload then cbe_core.js can only be included after your definition. For example:
Code:
<html>
<head>
<script>
window.onload = function() {
alert('in my onload');
}
</script>
<script src='cbe_core.js'></script>
</head>
<body>
</body>
</html>
And here's the example when you define window.onload through the body attribute:
Code:
<html>
<head>
<script>
function myOnload() {
alert('in my onload');
}
</script>
</head>
<body onload='myOnload()'>
...
<script src='cbe_core.js'></script>
</body>
</html>
I really don't like including cbe_core.js in the body element, but this is still the only suggestion I have for when the local handler is defined thru the body attribute.
Bookmarks