此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLLinkElement:integrity 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2018年4月⁩.

HTMLLinkElement 接口的 integrity 属性是一个字符串,包含浏览器可以用来验证所获取资源是否未经意外篡改的内联元数据。

它反映 <link> 元素的 integrity 属性。

一个字符串。

示例

html
<link
  id="el"
  href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
  rel="stylesheet"
  integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
  crossorigin="anonymous" />
js
const el = document.getElementById("el");
console.log(el.integrity); // 输出:“sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH”

规范

Specification
HTML
# dom-link-integrity

浏览器兼容性

参见