HTMLTitleElement:text 属性

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 接口的 text 属性表示文档标题的文本,仅包含文本部分;元素内的标签和其内容被剥离并忽略。

一个字符串。

示例

考虑一下示例:

html
<!doctype html>
<html lang="en-US">
  <head>
    <title>
      你好世界!<span class="highlight">这难道不精彩吗</span>真的吗?
    </title>
  </head>
  <body></body>
</html>
js
const title = document.querySelector("title");
console.log(title.text); // 产生:“你好世界!真的吗?”

如你所见,标签 span 和其内容被跳过。

规范

Specification
HTML
# dom-title-text-dev

浏览器兼容性

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
text

Legend

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

Full support
Full support