Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Problem with body and window onload event

  1. #1
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with body and window onload event

    Can anyone help with a proble I havem on my website

    I have the following two scripts on the same page which I downloaded from this site

    Chained Menu (http://www.dynamicdrive.com/dynamici...menu/index.htm) - which requires a <Body> onload event

    Daily Iframe Content (http://www.dynamicdrive.com/dynamici...dowiframe2.htm) - which requires a window.onload event

    I added both onload events into the <Body> tag

    onload="initListGroup('chainedmenu', document.clock.firstlevel, document.clock.secondlevel);clock();createhintbox();dayofweek_iframe() " (red is window onload - black is body onload)

    The problem I am having is that in Internet Explorer both the Body and window events load, the chained menu the iframe content displays.

    However if I open the page in Firefox only the former works (i.e. Iframe content does not display).

    The Iframe content script loads a different page depending on the day (hence the need for the window onlad event); I used this so i can display the sponsors in varying orders. I've temporarily overcome the problem by running an IFrame script which only runs one file so doesn't use the window onload event; but would like to go back if possible.

    Is there any way that I can run a Body and Window onload event which will display with firefox

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That's a way to do it. Looks like there might be other scripts involved as well. Set up a page that shows the problem and give us a link to it.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The page is

    http://www.stroudskittles.co.uk/signingon-old.html

    The Body Tag is

    <body bgcolor="silver" text="black" link="blue" vlink="green" alink="red" onload="initListGroup('chainedmenu', document.clock.firstlevel, document.clock.secondlevel);clock();createhintbox();dayofweek_iframe()">

    The initListGroup is for the chaned menu (which displays when it's the first onload), clock displays the Date and Time in the form, createhintbox displays thehint (?) at te end.

    The problem is the dayofweek_iframe, which is a window.onload event in the scroller which displays the sponsors (removed from <script language="JavaScript1.2" src="iframe-noonload.js"></script>). It should change depending on the day of the week.

    Under Firefox this will not display; under IE it works fine

    This is a window.onload event the others are Body onload events.

    Any help very much appreciated

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    It appears to be the hintbox.js script. At the end it has:

    Code:
    if (window.addEventListener)
    window.addEventListener("load", createhintbox, false)
    else if (window.attachEvent)
    window.attachEvent("onload", createhintbox)
    else if (document.getElementById)
    You see that highlighted line? It's an if with nothing to do if it is true. Firefox sees this as invalidating the entire hintbox script, so the call in the body onload event to createhintbox() throws an error. As a result, dayofweek_iframe(), which follows that never gets fired.

    Here's what I would do for now. get rid of that line so that you have:

    Code:
    if (window.addEventListener)
    window.addEventListener("load", createhintbox, false)
    else if (window.attachEvent)
    window.attachEvent("onload", createhintbox)
    And get rid of createhintbox(); from the body onload event as well. It's not needed because all modern browsers have either addEventListener or attachEvent.

    I say for now, because you might want to make all of these events into a single function and use the add/attach methods to fire that one function on window load. Or make each individual script do its window on load event that way. If you do it like that, each individual script could be added or removed without disturbing the others. But let's leave that for another time.

    In fact, more and more of the scripts being written today use some form of the add/attach methods for any load event they need. Many though do not need it. They either work completely differently (don't need the page to load first), or use the DOM ready event, which is faster.
    Last edited by jscheuer1; 03-17-2011 at 10:50 PM. Reason: English usage
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for you help i'll give it a try and let you know how it works

  6. #6
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have followed your suggestion; whilst is has resolved the issue regarding running both the Chained Menu and Sponsor Daily IFrace Content, it has now caused a problem in that the hintbox will not display

    On Internet Explorer I receive the following message

    Javascript Error

    Description:Object expected
    Source: http://www.stroudskittles.co.uk/signingon-old.html
    Line:105

    On Firefox I point to the ? but noting happens

    My best option here could be to remove the Hint Boxes, unless anyone has any other suggestions

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The hintbox-test.js appears to be an empty file. I only told you to remove that one line, not the entire script.

    If I add back the script, as is, from:

    http://www.dynamicdrive.com/dynamicindex16/showhint.htm

    It works fine in a local mock up. As long as you don't change anything else, I can put up a demo if you like.
    Last edited by jscheuer1; 03-18-2011 at 01:55 PM. Reason: add bit about mock up
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I see what I've done I've save it as a different name (I put suffix -test.js)

    Will upload and try again

    Thanks

  9. #9
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry I put suffix -new (to allow my existing files to remain unchanged).

    Problems with trying to make changes in a hurry

  10. #10
    Join Date
    Mar 2010
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorted, would help if I enter the crrect file name

    Thanks for your help

Bookmarks

Posting Permissions

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