📜  文档和窗口对象之间的差异

📅  最后修改于: 2022-05-13 01:56:39.374000             🧑  作者: Mango

文档和窗口对象之间的差异

在本文中,我们将看到 Document 对象和 Window 对象,它们的各种属性和方法,以及它们的实现和它们之间的区别。

文档对象:文档对象表示在浏览器中加载的网页。通过访问文档对象,我们可以访问 HTML 页面中的元素。借助文档对象,我们可以将动态内容添加到我们的网页中。可以使用window.document或仅使用文档来访问文档对象

句法:

document.property_name;

常用的文档对象的属性如下表所示:

文件属性:

文件方法:

句法:

下面列出了最常用的方法列表:

示例:此示例描述了 document.object 的实现。

HTML


HTML


 

     Window's Properties
    

 

    

GeeksforGeeks

         

          


输出:

窗口对象:窗口对象是 DOM 层次结构的最顶层对象。它表示显示网页内容的浏览器窗口或框架。每当屏幕上出现一个显示文档内容的窗口时,就会创建窗口对象。

句法:

下表列出了常用的 Window 对象的属性:

窗口属性:

窗口方法:

句法:

Window 对象常用的方法如下表所示:

示例:此示例描述了 window.object 的实现。

输出:

文档和窗口的区别:

document

window

It represents any HTML document or web page that is loaded in the browser.

It represents a browser window or frame that displays the contents of the webpage.   

It is loaded inside the window.

It is the very first object that is loaded in the browser.

It is the object of window property.

It is the object of the browser.

All the tags, elements with attributes in HTML are part of the document.

Global objects, functions, and variables of JavaScript are members of the window object.

We can access the document from a window using the window. document

We can access the window from the window only. i.e. window.window

The document is part of BOM (browser object model) and dom (Document object model)

The window is part of BOM, not DOM.

Properties of document objects such as title, body, cookies, etc can also be accessed by a window like this window. document.title

Properties of the window object cannot be accessed by the document object.

syntax:

      document.propertyname;

syntax:

window.propertyname;

example:

     document.title :  will return the title of the document

example:

window.innerHeight : will return the height of the content area of the browser