Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

HTML <script> integrity 属性

❮ HTML <script> 标签

示例

链接到 CDN,使用 integrity 和 crossorigin 属性

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous">
</script>

定义和用法

The integrity 属性允许浏览器检查获取的脚本,以确保如果源代码被操纵,则代码永远不会加载。

子资源完整性 (SRI) 是一个 W3C 规范,允许 Web 开发人员确保托管在第三方服务器上的资源未被更改。建议使用 SRI!

使用 SRI 时,网页保存哈希值,而服务器保存文件(在本例中为 .js 文件)。浏览器下载文件,然后检查它,以确保它与 integrity 属性中的哈希值匹配。如果匹配,则使用该文件;如果不匹配,则阻止该文件。

您可以使用在线 SRI 哈希生成器来生成完整性哈希值:SRI 哈希生成器


浏览器支持

表中的数字指定完全支持该属性的第一个浏览器版本。

属性
integrity 45.0 17.0 43.0 13.0 66.0

语法

<script integrity="filehash">

属性值

描述
filehash 外部脚本文件的哈希值

❮ HTML <script> 标签
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.