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 July 2015.

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 Standard
# dom-link-integrity

浏览器兼容性

BCD tables only load in the browser

参见