gpt4 book ai didi

html - Chrome : "Refused to apply inline style because it violates the following Content Security Policy directive..." 中的 css 内联样式错误

转载 作者:行者123 更新时间:2023-12-05 07:01:56 26 4
gpt4 key购买 nike

我有以下 html 页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline';"/>
<title>
</title>
</head>

<style>
.container {
display: flex;
display: -webkit-flex;
justify-content: center;
}

.label {
font-size: 20px;
text-align: center;
}

</style>

<body>
<div class="container">
<div class="label">Label content.</div>
</div>
</body>
</html>

尽管带有“unsafe-inline”的“Content-Security-Policy”标签没有应用样式,我在 Chrome 中看到以下错误:

"Refused to apply inline style because it violates the followingContent Security Policy directive: "default-src 'self'". Either the'unsafe-inline' keyword, a hash('sha256-daGc4DKtFpvn1iqhVz5mJJ4bXSwDGTnQKoxHdrHVEhc='), or a nonce('nonce-...') is required to enable inline execution. Note also that'style-src' was not explicitly set, so 'default-src' is used as afallback."

如何解决这个问题?

最佳答案

这可能是因为 HTML 中定义的 CSP 与您的网络服务器设置中的不同。对于 Apache,它位于文件“.htaccess”中。

但是,如果您添加一个具有全局“unsafe-inline”和“unsafe-eval”的 CSP,则根本没有安全性,CSP 变得有点无用。

此外,考虑为 HTML 和 CSS 创建不同的文件,并在需要时导入样式。

关于html - Chrome : "Refused to apply inline style because it violates the following Content Security Policy directive..." 中的 css 内联样式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63708633/

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