TrustedScriptURL
>备注: 此特性在 Web Worker 中可用。
可信类型 API 的 TrustedScriptURL 接口表示一个可以被开发者插入注入汇聚点的、作为外部脚本的 URL 解析的字符串。这些对象由 TrustedTypePolicy.createScriptURL() 创建,因此没有构造函数。
TrustedScriptURL 对象的值在对象被创建时设置,且不允许通过 JavaScript 修改,因为其没有暴露 setter 方法。
实例方法
TrustedScriptURL.toJSON()-
返回一个表示
TrustedScriptURL对象的字符串,与TrustedScriptURL.toString()的返回内容相同。此方法会由JSON.stringify()自动调用。 TrustedScriptURL.toString()-
包含净化过的 URL 的字符串。
示例
常量 sanitized 是一个通过可信类型策略创建的对象。
js
const sanitized = scriptPolicy.createScriptURL(
"https://example.com/my-script.js",
);
console.log(sanitized); /* TrustedScriptURL 对象 */
规范
| 规范 |
|---|
| Trusted Types> # trused-script-url> |