gpt4 book ai didi

javascript - 在 Firefox 中出现 "undeclared character encoding"错误

转载 作者:行者123 更新时间:2023-12-03 12:36:28 26 4
gpt4 key购买 nike

我正在处理 JS SPA book并注意到我在 Chrome 和 Firefox 中得到不同的结果。这是代码...

<!doctype html>
<html>
<head>
<title>SPA Chapter 1 section 1.2.2</title>
<style type="text/css"></style>
<script type="text/javascript">
var prison = function () {
console.log('made it to prison');
};
prison();
</script>
</head>
<body>
<div id="spa"></div>
</body>
</html>

又好又简单...不是吗?在 Chrome 中,我在控制台中得到了“入狱”的预期结果。然而,在 FF 中只收到一个错误,内容为...

The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol.

什么给了? FF webdev 控制台中是否缺少我的设置?

最佳答案

当您在开发工具中启用控制台日志记录时,Firefox 在控制台日志中显示预期结果。它还显示一条消息,在某些版本中被归类为错误消息,但不影响功能。它实际上是一条信息性消息,表明页面的字符编码未以任何方式声明;请参阅W3C page on encodings .

控制控制台日志中显示内容的方式取决于您使用的开发工具。使用built-in dev tools在当前版本的 Firefox(称为 Aurora)中,您可以使用 Ctrl Shift K 调用它,请确保启用“日志记录”(显示为黑色,而不是灰色),如下图所示:

enter image description here

您需要决定字符编码。对于任何现代应用程序,很少需要考虑除 UTF-8 之外的任何其他选项。您可以通过在文本编辑器中将 HTML 文件保存为“UTF-8 with BOM”和/或使用标签 <meta charset=utf-8> 来声明它。在 head部分。如果您只使用后者,并且页面是通过 HTTP 发送的,您应该确保服务器不会在 Content-Type 中发送冲突的信息。 HTTP header 。

关于javascript - 在 Firefox 中出现 "undeclared character encoding"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23716279/

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