![]() |
| ||
| body.onload += "XX" I'm trying to append a function to the body tag's onload event... <body onload="Do_This();"...> The alert reports "undefinedDo_This();". The Do_This() function does load (and run) but I want both funcions to run on the onload event. The body tag is in a php "header" file that is included in the file the holds the script. Thanks |
| ||
| Re: body.onload += "XX" You can either define a third function, which would have the sole purpose of calling the other two functions. Or, you can comma separate the two functions in your onload attribute. Or, you can concantenate them with the "&&" operator: <body onload="return (Do_This() && Do_That())" > (which is a useful construct if the functions return booleans). Lastly, you can just include the "And_This()" function in a separate script body at the very end of your document. It will run "inline" when the browser encounters it. |
| ||
| Re: body.onload += "XX" This page demonstrates a technique that can be used to add functions to a body onload, or similar attribute. The beauty of this is that it can be used in situations where your project does not control ownership of the header section of the page, but you want to assign onload or similar behaviours to a page, without destroying the behaviour that already exists. <html> What happens here is the loadBody and unloadBody functions are called inline when the page is being drawn. At this stage the body.onload attribute has been set (you access this using the window.onload attribute). If you print this attribute, you will notice that it is a function, with the initially defined onload function forming the body of the function. This way the javascript engine preserves the arguments that have been provided. The loadBody function then stores the current function in a global pointer variable. That can then be called as a function in the newly defined onload function. This has been tested in Internet Explorer 6.0.2800.1106 and Mozilla Firefox 1.0.3 with build string: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3 |
| All times are GMT -4. The time now is 5:52 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC