Home >
Article > Web Front-end > html5 guide-2. How to operate document metadata_html5 tutorial tips
html5 guide-2. How to operate document metadata_html5 tutorial tips
WBOYOriginal
2016-05-16 15:50:151375browse
Today’s content is about how to operate document objects. 1. Manipulate Document Metadata First, let’s take a look at the related attributes: characterSet: Get the encoding method of the current document. This attribute is read-only; charset: Get Or set the encoding method of the current document; compatMode: Get the compatibility mode of the current document; cookie: Get or set the cookie object of the current document; defaultCharset: Get the browser's default encoding method; defaultView: Get the window object of the current document; dir: Get or set the text alignment of the current document; domain: Get or set the domian value of the current document; implementation: Provide the supported dom features information; lastModified: Get the last modified time of the document (if there is no last modified time, return the current time); location: Provide the URL information of the current document; readyState: Return the status of the current document, This attribute is a read-only attribute; referrer: Returns the document url information connected to the current document; title: Gets or sets the title of the current document. Look at the following example:
Copy the code
The code is as follows:
example
< /body>
Results (different browsers may display different results):
2. How to understand compatibility mode The compatMode attribute tells you how the browser handles the current document. There is so much non-standard HTML out there that browsers will try to display these pages even though they don't conform to the HTML specification. Some content relies on unique features that existed during the early days of the browser wars, and these properties are not compliant with the specification. compatMode will return one or two values, as follows: CSS1Compat: the document conforms to a valid html specification (not necessarily html5, the verified html4 page also returns this value); BackCompat: the document contains non-compliant feature, triggering compatibility mode. 3. Use the Location object document.location returns a Location object, providing you with fine-grained address information of the document and allowing you to navigate to other documents. protocol: Get or set the protocol of the document url; host: Get or set the host information of the document url; href: Get or set the address information of the document; hostname: Get or set the document's address information Host name; search: Get or set the information in the query part of the document url; hash: Get or set the information in the hash part of the document url; assign(): Navigate to a specified url; replace(): Remove the current document and navigate to the specified url; reload(): Reload the current document; resolveURL(): Change the relative path to Absolute path. Look at the following example:
<script> <br>document.onreadystatechange = function () { <br> if (document.readyState == "interactive") { <br>document.getElementById("pressme").onclick = function () { <br>document.getElementById("results").innerHTML = "Button Pressed"; <br>} <br>} <br>} <br></script>
above The code uses the readystatechange event to achieve the effect of delayed execution. The value of readystate will become interactive only after the entire page is parsed and contacted. At this time, the click event is bound to the pressme button. This operation can ensure that the required html elements are present and prevent errors from occurring. 6. Get information about the implementation of dom attributes The document.implementation attribute helps you understand the browser's implementation of dom attributes. This property returns a DOMImplementation object, which contains the hasFeature method. You can use this method to understand the browser's implementation of a certain property.
Copy code
The code is as follows:
Example
<script> <br>var features = ["Core", "HTML" , "CSS", "Selectors-API"]; <br>var levels = ["1.0", "2.0", "3.0"]; <br>document.writeln("<pre class="brush:php;toolbar:false">"); <br> for (var i = 0; i < features.length; i ) { <br>document.writeln("Checking for feature: " features[i]); <br>for (var j = 0; j < levels .length; j ) { <br>document.write(features[i] " Level " levels[j] ": "); <br>document.writeln(document.implementation.hasFeature(features[i], levels[j ])); <br>} <br>} <br>document.write("</pre>") <br></script>
Effect:
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn