SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 81 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

oldsrc = this.src; // copy the current path into a custom property
this.src = 'newimage.gif';
}
image.onmouseout = function()
{
this.src = this.oldsrc; // use the old path that we specified
}
Accessing Elements Before the Page Loads
In all the previous examples, the assumption was made that the object you were looking for
existed when you asked for it. The browser makes each element on the page available via
JavaScript as it reads and renders each one. However, because JavaScript code is normally
included in the head of the document, the body of the document is unavailable to you. Trying
to access an object before it is available will generate an error. Therefore, before you can interact
with any of the elements on the page, you have to wait until the page is loaded.
As you just saw, you can wait until the page loads by using the window.onload event:
var el = document.getElementById("myelement"); // will generate an error message
window.onload = function()
{
var el = document.getElementById("myelement"); // yay! I've got my element!
}
Oh, but there??™s a catch. (There had to be one.) The catch is that the onload event doesn??™t
fire until the entire page and all its images have been downloaded. The user could be interacting
with the page well before the onload event actually is run. To get around this, you have
some options, but unfortunately, there??™s no silver bullet solution.


Pages:
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
druga wojna światowa Free English grammar and study guid hotel jelenia góra Russian bride counter strike 1.6