Click to See Complete Forum and Search --> : an onload even outside of the body tag?


screamingbuddha
12-18-2002, 01:34 PM
I'm working in a template environment, and I can't change the <body onLoad> tag (it already had a muti-use function on it.

On the specific page I'm working on, I need some layer visibilities changed (dependant on a cookie) which seemingly can only can be done in the onLoad event.

so I need to add to or capture the onLoad for one page, and no others with a script included in the body data? (and of course it needs to be cross-broswer compliant 5+)

or is this impossible?

swon
12-18-2002, 01:51 PM
there are a few ways:

-------------------------------
</body>
<script language="javascript">
document.onload= yourfunction
</script>
</html>
-------------------------------
or

<body onload="yourexistingfunction();nextfunction()">

-------------------------------
or you can put it into your existing function.

utahsaint
01-15-2003, 05:10 PM
Unfortuantly I have also tried the document.onLoad. The only way I could get it to partialy work was to put a setTimeout on it also. This way it times for a designated time before calling the function. But even this does not work if the user is on a slower connection. Is there a better way????

document.onload = setTimeout('read_cookie()',150);

Charles
01-15-2003, 05:22 PM
Try:

<script type="text/javascript">
<!--
window.onload = function () {alert()}
// -->
</script>

You need to use the onunload method of the Window object and you need to use an anonymous function.

utahsaint
01-15-2003, 05:32 PM
Thanks a ton why thats not anywhere else I will never know.

utahsaint
01-16-2003, 04:06 PM
Well that did work great however it causes even more of headach. You see my issue is that I need this in the JavaScript portion but I also have access to all the body tags. The problem arises when the body tag has something in it this tag overwrites it. I would just change the body tags on the site but there are like 2000 pages and that could be a headache. So is there a way to use this and not overwrite the body onLoad functions?

Charles
01-16-2003, 04:38 PM
Try

<script type="text/javascript">
<!--
window.onunload1 = window.onunload;
window.onload = function () {window.onunload1(); alert()}
// -->
</script>

utahsaint
01-16-2003, 05:20 PM
That still overwrote any function that was directly called by the body tag itself. Thanks for trying I am just going to have to put this into the body tag.


IE here is the full issue if anyone else knows of solution.


<script language="JavaScript">

function init(){
// do some initializing of stuff.
}
function something(){
// do something else
}
window.onunload1 = window.onunload;
window.onload = function () {window.onunload1(); something()}
// -->
</script>

<body onLoad="init()">

Now normally you would just change the body tag but this body tag is in a template and included with cold fusion on several pages IE over 1000. I wrote a menu that needs to be initilized but not by putting this in the body tag. I think that I will just have to though because no other solutions are working. The solution above works but overwrites the init in the body tag.

Charles
01-16-2003, 05:32 PM
Can you edit your init() function with ease?

utahsaint
01-17-2003, 09:46 AM
I think the easiest solution is to default the variable for the header to call the menu. Then on the other pages I will just have to change the body tag. I checked through the website and this came out to be roughly 65 pages. Not too bad still a ton but not as bad as I thought originally. Wish there was a different solution though.

johnywhy
07-11-2010, 04:17 PM
in this example, where do i put the name of the function i'm trying to call?

<script type="text/javascript">
<!--
window.onload = function () {alert()}
// -->
</script>

do i need to include the "unload" stuff?

thanks