assigned onload event outside of body tag - not working

i have this

document.onload=resizeToContent;


but the function is not called, the call cannot be in the body tage as the page is generated dynamically and the function is only there under specific conditions so i added the above line within the conditiona statements, the function and the call line appear on the page but the function is not called
LVL 25
James RodgersWeb Applications DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dorwardCommented:
window.onload = function() {
  resizeToContent; /* Should that be resizeToContent(); ? */
}

Or perhaps you have Mozilla and have turned on the browser's ability to block such irritating scripts (i.e. the resizing of windows - I'm quite capable of making the window the size that I want).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ZontarCommented:
window.onload = function() {  resizeToContent(); };

is the correct syntax. However, it's not necessary to use an anonymous function in this case, as

  window.onload = resizeTo Content;

would also be correct.

Your problem is that there is no such thing as a document.onload event, it's window.onload.
0
James RodgersWeb Applications DeveloperAuthor Commented:
used your suggestion and changed it to this

window.onload=resizeToContent;

and worked fine, thanks!

>>...such irritating scripts (i.e. the resizing of windows ...

i'm not resizing the window but a table that exceeds the page length.

its a dynamically generated table with a minimum of 50 rows and a 'header' section that is created based on user input so the header can be very long! so as per clients specs the table was not to exceed the page length so i have it in a scollable div that resizes based on the window size and header size
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

James RodgersWeb Applications DeveloperAuthor Commented:
sorry Zontar, i used the code provided by dorward, it led me to the solution you posted
0
ZontarCommented:
dorward's solution was not correct and mine was, so you awarded the question to him? Whatever...
0
James RodgersWeb Applications DeveloperAuthor Commented:
>>dorward's solution was not correct and mine was, so you awarded the question to him? Whatever...

awarding of the points was based upon the fact that dorward provided me with an answer from which i was able to extract the right answer, that was why i posted the apology...so you would understand why i had chosen dorwards answer instead of yours...

your answer was right, but i had already achieved the answer by using dorwards input so i thought s/he should get the points

from the EE FAQ
http://www.experts-exchange.com/help/qnaFAQ.jsp#3
It is the Asker's right -- and responsibility -- to decide which comments best resolve his problem.
0
edwinlamvancouverCommented:
For all:

This maybe slightly off-subject but just to share this which took me hours to figure out. My experience: be cautious of having more than one window.onload functions for the same window, even in two or more separate physical htm/php files (especially in two or more files.) Only one of them may fire.

Hope that helps somebody.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.