Skip to main content

Bug Tracker

Side navigation

#10010 closed bug (invalid)

Opened August 10, 2011 04:07AM UTC

Closed August 10, 2011 01:55PM UTC

Double Window.load not working

Reported by: quibski@gmail.com Owned by:
Priority: low Milestone: None
Component: event Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:
Description

1. The version(s) of jQuery affected: 1.62 and earlier versions

2. The browser (or browsers) that you are able to reproduce the bug in, including version numbers: FF 5.01 and other browsers

3. The operating system (or operating systems) you experienced the bug on: OS X LION and other OS

4. ''Step-by-step instructions on how to reproduce the issue, including any required system configuration changes:''

$(window).load() is called again because of various reasons. Mine is that a form loaded once and then may be reloaded again using ajax call.

Basically it can be reproduced using 2 files - A) Form.php B) Fields.php . File A will include File B using #include ... upon browser load, the window.load found in B will execute perfectly. However, using various Ajax to replace HTML calling file B again, the HTMLS will be loaded properly however window.load does not occur anymore.

5. ''A description of what you expect to happen, and what actually happens:''

Contents of $(window).load() should be executed even if the window was formerly loaded

6. Sample simplified version using only one file to demonstrate: http://jsfiddle.net/wUyzU/


$(document).ready(function()
{
    $("#content").append("Ready");

    $(document).ready(function()
    {
        $("#content").append(" Again! ");

    })
})
    
$(window).load(function()
{
    $("#content").append("Load");                   

    $(window).load(function()
    {
        $("#content").append(" Twice!");                  

    })
})
Attachments (0)
Change History (4)

Changed August 10, 2011 04:37AM UTC by rwaldron comment:1

component: unfiledevent
priority: undecidedlow
resolution: → wontfix
status: newclosed

I don't think it makes sense for jQuery to add code to handle such an edge case. Either way, it works properly when they're no nested:

http://jsfiddle.net/rwaldron/wUyzU/1/

Changed August 10, 2011 04:51AM UTC by quibski@gmail.com comment:2

Hi rwaldron,

I think the scenario makes sense. Although the sample given is nested. Imagine in which a user may load through ajax a html with scripts having $(window).load() and not $(document).ready();

Changed August 10, 2011 01:55PM UTC by dmethvin comment:3

resolution: wontfix
status: closedreopened

Changed August 10, 2011 01:55PM UTC by dmethvin comment:4

resolution: → invalid
status: reopenedclosed

The semantics of the .ready() method are different from those of the load event. Once the document becomes ready it stays ready. It's not an event, but a state. Any ready handler attached at any point afterwards will run immediately.

The load event is different; a load event is fired *once* by the browser. A new handler attached then, or anywhere afterwards, will not fire because the browser never fires load again.

Although a ready *event* does exist and you can attach to it with .bind(), it fires once the same way the load event does. You should use .ready() instead.