Opened 11 years ago
Closed 11 years ago
#10010 closed bug (invalid)
Double Window.load not working
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | event | Version: | 1.6.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
- The version(s) of jQuery affected: 1.62 and earlier versions
- The browser (or browsers) that you are able to reproduce the bug in, including version numbers: FF 5.01 and other browsers
- The operating system (or operating systems) you experienced the bug on: OS X LION and other OS
- 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.
- 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
- 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!"); }) })
Change History (4)
comment:1 Changed 11 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Resolution: | → wontfix |
Status: | new → closed |
comment:2 Changed 11 years ago by
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();
comment:3 Changed 11 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
comment:4 Changed 11 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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.
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/