知识林
当前位置:知识林 » 网站前端开发 » HTML_DOM » Document Object properties (英文)

Document Object properties (英文)

来源: 知识林
Properties Description
body References the body element of the page. From there,you can then access other nodes contained within the body.
body.offsetWidth, body.offsetHeight Returns the width and height of the entire document, respectively.
compatMode Returns the compatibility mode of the current document, specifically, whether the page is rendered in Quirks or Stricts mode. The two possible values returned are "BackCompat" for Quirks and "CSS1Compat" for Strict. Useful for determining the doctype setting of the page and executing different code accordingly.

Example(s):

if (document.compatMode=="CSS1Compat")
// execute code for page with a valid doctype

document.documentMode

IE8 only property

IE8 property that detects the document mode used by the browser to render the current page. Because IE8 can render a page in various different modes depending on the page's doctype plus the presence of certain HTML elements, documentMode returns a different number depending on the mode the page is being rendered in. They are
 
5 Page is running in IE5 mode (aka "quirks mode").
7 Page is running in IE7 standards mode.
8 Page is running in IE8 standards mode.

Microsoft recommends you use documentMode over compatMode to detect a webpage's doctype. See Defining Document Compatibility for more info.

doctype Read-only property that returns the Document Type Definition (DTD) of the current document, or null if the page doesn't contain a DTD. Not supported in IE as of IE6.
documentElement References the root element of the document, in the case of HTML documents, the html element. This read only property is useful for accessing all elements on the page, such as the HEAD.

Example(s):

entiredoc = document.documentElement;
var elements=entiredoc.getElementsByTagName("*")
for (i=0; i<elements.length; i++)
alert(elements[i].tagName)

domain Gets/sets the domain of the current document. Useful in cross domain scripting when one domain is to communicate with another.

Example(s):

document.domain="javascriptkit.com"

implementation Returns the DOM implementation of the current document.
ownerDocument Returns a reference to the document object that contains the current element/node.

var ownerdoc=document.getElementById("adiv").ownerDocument

readyState

IE property. Supported in Opera 9+, Chrome, and FF 3.6+ as well.

Returns the loading status of the document. It returns one of the below 4 values:
 
uninitialized The document hasn't started loading yet.
loading The document is loading.
interactive The document has loaded enough whereby user can interact with it.
complete The document has fully loaded.

Use the onreadystatechange event handler to react whenever the readyState of the document changes. For example:

document.onreadystatechange=function(){
 if (document.readyState=="complete"){
  alert("Document loaded fully!")
 }
}

styleSheets[] An array referencing all stylesheet objects on the page, whether they are defined using the <style> or <link> tag.
title Specifies the title of the document. Read/write in modern browsers.
URL A string that specifies the complete URL of the document.

今天

Copyright © 知识林 All Rights Reserved.   吉ICP备13001611号-1