Results 1 to 3 of 3

Thread: calling a function from within another onload function

  1. #1
    Join Date
    Jun 2012

    calling a function from within another onload function

    Why will this work:

    window.onload = function () {

    and this won't ?

    window.onload = showMeTheDoc('65.xml');

    I am inquiring in regards to the principle of calling a function from within another function.
    Why does that work as opposed to calling a function straight away?


  2. #2
    Join Date
    Jul 2003
    The City of Roses
    The difference is when the showMeTheDoc function is invoked, and what is assigned to window.onload.

    In your first snippet, you're assigning a reference to a function. When the onload event fires, that function reference is executed, which then executes showMeTheDoc.

    In your second snippet, the showMeTheDoc function is being executed immediately rather than waiting for the onload event, and the return value of that invocation is what is then assigned to window.onload.

  3. #3
    Join Date
    Jun 2012
    hmm... I am still not clear why:

    the first snippet will return a result but the second snippet won't ...
    since they are both running for the first time - right?

    If so then why does something similar - like the below works since it is directly assigned to the onclick event? (just like the window.onload event of my example) ...?

    <a href="#" class="button" onclick="function()"> click me </a>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center