HTMLTitleElement

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.

HTMLTitleElement 接口由文档的 <title> 实现。此元素继承 HTMLElement 接口的所有属性和方法。

EventTarget Node Element HTMLElement HTMLTitleElement

实例属性

从其父接口 HTMLElement 继承属性。

HTMLTitleElement.text

表示文档标题文本的字符串。

实例方法

无特定方法;从其父接口 HTMLElement 继承方法。

示例

请勿混淆 document.titledocument.querySelector('title')

前者只是一个 setter/getter 方法,用于设置或读取文档标题的内部文本值,后者是 HTMLTitleElement 对象。因此你不能写:document.title.text = "Hello world!";

相反,你可以简单地写:document.title = "Hello world!";,这相当于 document.querySelector('title').text = "Hello world!";

规范

Specification
HTML
# htmltitleelement

浏览器兼容性

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
HTMLTitleElement
text

Legend

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

Full support
Full support

参见

  • 实现此接口的 HTML 元素:<title>