document.implementation

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

概要

返回一个和当前文档相关联的DOMImplementation对象。

语法

DOMImpObj = document.implementation;

示例

js
var modName = "HTML";
var modVer = "2.0";
var conformTest = document.implementation.hasFeature(modName, modVer);

alert("DOM " + modName + " " + modVer + " supported?: " + conformTest);

// alerts with: "DOM HTML 2.0 supported?: true" if DOM Level 2 HTML module is supported.

可以在一致性章节中查看可用的一系列 DOM2 级模型名称(例如:Core, HTML, XML 等等)。

说明

W3C 的 DOM1 级建议值规定了一种检测浏览器对某个 DOM 模型是否支持的方法——hasFeature 方法(请参考上边的例子以及这篇文章 What does your user agent claim to support?)。如果它可用的话,那么 DOMImplementation 接口的其他方法就可以为操作文档以外的内容提供一些服务了。例如,DOMImplementation 接口包含一个 createDocumentType 方法,它可以为实例管理的文档创建对应的 DTD 文档定义。

方法

名称 动作 返回值
createDocument (namespaceURI, qualifiedNameStr, DocumentType ) document
createDocumentType ( qualifiedNameStr, publicId, systemId ) DocumentType
createHTMLDocument ( title ) document
getFeature ( feature, version ) DOMObject
hasFeature ( feature, version ) Boolean

规范

Specification
DOM
# ref-for-dom-document-implementation①

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
implementation

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Gecko 引擎的特别说明

  • 从 Gecko 19.0 开始hasFeature方法总是返回 true。