大网数据广告活动
Web 标准与前端开发

HTMLScriptElement: innerText property

· 52CE 我爱测

[!WARNING] > This property represents the text content of a script element, which may be executable depending on the script type. > APIs like this are known as injection sinks, and are potentially a vector for cross-site scripting (XSS) attacks. > > You can mitigate this risk by

HTML DOM

[!WARNING] This property represents the text content of a script element, which may be executable depending on the script type. APIs like this are known as injection sinks, and are potentially a vector for cross-site scripting (XSS) attacks.

You can mitigate this risk by always assigning TrustedScript objects instead of strings and enforcing trusted types. See Security considerations for more information.

The innerText property of the HTMLScriptElement interface represents the text content of the script element. It behaves in the same way as the HTMLScriptElement.textContent and HTMLScriptElement.text properties.

Value

Getting the property returns a string containing the scripts's text.

Setting the property accepts either a TrustedScript object or a string.

Exceptions

Description

The innerText property of the HTMLScriptElement interface represents the text content inside the script element.

For an executable script (that is, a script whose HTMLScriptElement/type indicates that it is a module or classic script), this text is inline executable code. For other types it might represent an import map, speculation rules, or some other kind of data block.

Note that if the HTMLScriptElement/src property is set the content of the innerText property is ignored.

The innerText property is also defined on HTMLElement.innerText and can hence be used with other elements. When used with other elements, the property does not expect or enforce the assignment of a TrustedScript.

Security considerations

See security considerations in HTMLScriptElement.textContent (the considerations are the same for text, textContent and innerText properties).

Examples

See the examples in HTMLScriptElement.textContent.

Specifications

Browser compatibility

See also

  • HTMLElement.innerText

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。