Difference Between Window And Document In Jquery
Solution 1:
Phew . . . that's actually a lot bigger of a question than you may realize. :)
The Extremely Short Answer is . . .
The window
object represents the container that the document
object is displayed in. In fact, when you reference document
in your code, you are really referencing window.document
(all properties and methods of window
are global and, as such, can be referenced without actually specifying window
at the beginning . . . e.g., document
= window.document
and alert()
= window.alert()
).
The document
object is the currently loaded DOM document . . . so, if you go to http://www.stackoverflow.com, the document
object would be all of the HTML, JS, CSS, etc. that are loaded to make up the StackOverflow home page. If you click on the link to this question, the document
is now all of the same kinds of assets that make up the page for this question. When you change documents
though, you are still in the same window
(though some of the properties of the window
have changed).
For LOTS of information on the two objects (including standard properties and methods), check out these links:
- the
window
object - https://developer.mozilla.org/en-US/docs/Web/API/Window - the
document
object - https://developer.mozilla.org/en-US/docs/Web/API/document
One last note: While not completely accurate, if you are a visual person, you can think of the window
as the browser window or tab that you have open to view web pages . . . you may move through many document
s as you are surfing, but, if you never change to a different tab, you are always in the same window
.
Solution 2:
This article explain benefits of both
In short term:
window
- you can handle if user interact with window (open, close, etc..)
document
- is a content of window and you can handle if user iteract with content (watched, fired some events like a click, change etc)
But keep in mind !! They are different objects and does different things.
Solution 3:
The window is the first thing that gets loaded into the browser. This window object has the majority of the properties like length, innerWidth, innerHeight, name, if it has been closed, its parents, and more. What about the document object then?
The document object is your html, aspx, php, or other document that will be loaded into the browser. The document actually gets loaded inside the window object and has properties available to it like title, URL, cookie, etc. What does this really mean? That means if you want to access a property for the window it is window.property, if it is document it is window.document.property which is also available in short as document.property.
For More detail with screenshot read following article
http://eligeske.com/jquery/what-is-the-difference-between-document-and-window-objects-2/
Post a Comment for "Difference Between Window And Document In Jquery"