body onload event breaks admin links
bpedigo - August 9, 2006 - 01:42
| Project: | PHPTemplate |
| Version: | HEAD |
| Component: | Code |
| Category: | support request |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I can't add an onload event to the body tag of my template without breaking the admin pages. What's the workaround? I keep reading about the addLoadEvent() function but I don't understand how to integrate it into my php template.

#1
Calling onload functions in this way breaks compatibility with certain scripts that depend upon the page being loaded first. For example, Project 7's Pop Menu Magic's init function must be in the body/onload attribute to work properly.
#2
So how do I do it the right way? I can't figure it out. :(
#3
There are TONS of us who are having the same issue. Please, is there a workaround to call our own onload functions? If not please fix the issue.
Regards,
Phil
#4
I was finally able to make this work.
I done it in this example, but you may choose to escape the script block with a comment or CDATA block as needed for validation purposes. There is a lengthy discussion of this topic somewhere... I can't remember where.
Place the following code at the end of your page head...
<script type="text/javascript">
function MyAddOnload(func)
{
var oldOnload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldOnload();
func();
}
}
}
function MyInit()
{
DoStuffHere();
}
Then, place this immediately after the body tag opens.
<script type="text/javascript">MyAddOnload(MyInit);
</script>
#5
Here's the article on correct script escaping in XHTML.
http://en.wikibooks.org/wiki/Programming:Complete_PHP/Escaping_from_HTML...
You'll also want to close that first script block... :)