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

SVGAnimatedString: baseVal property

· 52CE 我爱测

[!WARNING] > The `baseVal` property can be used to set the non-animated value of a reflected attribute. > In the case of SVGScriptElement/href this property represents the URL of an external script loaded into the SVG script element. > APIs like this are known as injection sinks,

SVG

[!WARNING] The baseVal property can be used to set the non-animated value of a reflected attribute. In the case of SVGScriptElement/href this property represents the URL of an external script loaded into the SVG script element. 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 having a Content Security Policy (CSP) that restricts the locations from which scripts can be loaded, and by always assigning TrustedScriptURL objects instead of strings, and enforcing trusted types. See Security considerations in SVGScriptElement.href for more information.

The baseVal property of the SVGAnimatedString interface gets or sets the base value of the given attribute.

This is the value of the reflected attribute before any animations are applied.

Value

Getting the property returns a string that represents the non-animated value of the reflected attribute, if it has been set. If the reflected attribute is not specified but has an alternative deprecated version that has been set, then its value will be returned instead. If neither reflected attribute is set, then the property will return an initial value for the reflected attribute if one exists, and otherwise the empty string ("").

The property must be set to a TrustedScriptURL if the reflected attribute's element is an SVGScriptElement and Trusted Types are enforced by a CSP. For all other cases, the value can be a string (or an object that can be resolved to a string). The property sets the value of the reflected attribute if it is defined, but will set the alternative deprecated version of the reflected attribute if it is defined and the reflected attribute is not.

Note that TrustedScriptURL or any other trusted type can be set for baseVal on any element, because the trusted types resolve to strings. However TrustedScriptURL must be used for SVGScriptElement/href when trusted types are enforced.

Exceptions

  • TypeError
    • : Thrown if the reflected attribute's element is SVGScriptElement, and the property is set to a string when Trusted Types are enforced by a CSP, and no default policy is defined.

Specifications

Browser compatibility

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

资料来源与适用范围

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

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

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