gpt4 book ai didi

javascript - amp-script 未找到脚本哈希。 amp-脚本[脚本 ="hello-world"]

转载 作者:行者123 更新时间:2023-12-02 21:21:57 29 4
gpt4 key购买 nike

我尝试使用 amp 脚本,但收到此错误:

“[amp-script] 脚本哈希未找到。amp-script[script="hello-world"].js 必须在元[name="amp-script-src"]中包含“sha384-BdjJFLYaZaVK-HgidJ2OFtpYsczYQc4N42NgKo7MOkF88iPbpdDWPgf86Y6PyEKO” .参见https://amp.dev/documentation/components/amp-script/#security-features。”

error image

<!doctype html>
<html amp lang="en">
<head>
<meta charset="utf-8">
<meta class="trackPerformanceTag" content="AMP">
<script src="https://cdn.ampproject.org/v0.js" async></script>
<script async custom-element="amp-script" src="https://cdn.ampproject.org/v0/amp-script-0.1.js"></script>
<meta name="amp-script-src" content="sha384-generated-sha">
<title>title</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">

</head>
<body>

<amp-script layout="container" script="hello-world" class="amp-script-sample">
<button id="hello2">Click!</button>
</amp-script>

<script id="hello-world" type="text/plain" target="amp-script">
const button = document.getElementById('hello2');
button.addEventListener('click', () => {
const h1 = document.createElement('h1');
h1.textContent = 'Hello World 2!';
document.body.appendChild(h1);
});
</script>

</body>
</html>

最佳答案

您需要复制开发工具控制台中错误消息中显示的完整哈希值。

在这种情况下;

sha384-BdjJFLYaZaVK-HgidJ2OFtpYsczYQc4N42NgKo7MOkF88iPbpdDWPgf86Y6PyEKO

并将其粘贴到标题中的元数据中:

<meta name="amp-script-src" content="PUT_THE_SHA_HERE">

每次您更改脚本中的某些内容时,都会生成新的哈希值,您需要再次复制/粘贴它。

See the screen with error form the dev tools console

关于javascript - amp-script 未找到脚本哈希。 amp-脚本[脚本 ="hello-world"],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60819910/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com