PDA

View Full Version : Add onload to body tag



mtran
10-02-2008, 03:50 PM
Hi,

It looks like a simple question but I haven't figured out how to do it yet.
I have a javascript function that needs to be activated with onload in the body tag.

Everything [html and javascript] works fine on my desktop and my own server - where I have access to change the <body> tag. But where I'm working for right now, using CMS, and I don't have access to change the body tag. How do I get around it and dynamically add onload to the body.

jscheuer1
10-02-2008, 03:57 PM
It depends upon what you do have access to, and if there is only one event to perform onload or not. If you have access to edit the script used by the page and there are no other onload events for that page either coded in another script you have for that page or in some other script assigned to that page by anyone/anything else, you can just put your onload in your script code. Say you wanted to have:


<body onload="doSomething();">

Instead, in your script you could put:


window.onload = function(){
doSomething();
};

codeexploiter
10-03-2008, 05:55 AM
But where I'm working for right now, using CMS, and I don't have access to change the body tag

May be your CMS provides another means of achieving the effect you want. Which CMS you use?