Firefox 3语法错误与外部CSS

时间:2021-10-20 00:47:46

I get a strange syntax error in Firefox 3.0.10/Leopard when using the following html/css:

使用以下html / css时,我在Firefox 3.0.10 / Leopard中出现了一个奇怪的语法错误:

foo.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
<head>
  <link rel="stylesheet" href="foo.css"/>
</head>
<body>
Foo
</body>
</html>

foo.css:

div {
  color: #FF0000;
}

and the error I get in the console is:

我在控制台中得到的错误是:

Error: syntax error
Source File: file://path/to/foo.css
Line: 1, Column: 1
Source Code:
div {

It's not the CSS, because pasting it into the body of an inline STYLE tag works fine. It's not the link tag, because pointing the HREF to stack overflow's css file doesn't give an error. Feels like a Firefox bug, but I can't find any documentation on it. Is this a known issue, and is there a workaround? It makes it hard to debug or validate.

这不是CSS,因为将其粘贴到内联STYLE标签的主体中可以正常工作。它不是链接标记,因为将HREF指向堆栈溢出的css文件不会产生错误。感觉像Firefox的bug,但我找不到任何文档。这是一个已知问题,是否有解决方法?这使得调试或验证变得困难。

Thanks.

5 个解决方案

#1


It's giving you the error on the first character in the file, which is a 'd', which rules out things like "hidden" special characters to me. I'd guess that firefox isn't able to open the file locally for whatever reason, or that the file was accidentally saved with an encoding that, although it displays fine in the dialog box, doesn't parse normally. Perhaps it's saved as Unicode by mistake?

它给你错误的文件中的第一个字符,这是一个'd',它排除了像我这样的“隐藏”特殊字符之类的东西。我猜想firefox无论出于何种原因都无法在本地打开文件,或者文件意外地保存了一个编码,尽管它在对话框中显示正常,但是没有正常解析。也许它被错误地保存为Unicode?

If you could link us to the actual file it would help, since your syntax (despite the markup not being exactly valid, but I don't think that's it) is perfect in the .css file you pasted in.

如果您可以将我们链接到实际文件,那将会有所帮助,因为您的语法(尽管标记不完全有效,但我认为不是这样)在您粘贴的.css文件中是完美的。

#2


The answer turned out to be "Turn off extensions (it was YSlow)" as suggested in the comments.

根据评论中的建议,答案结果是“关闭扩展(它是YSlow)”。

#3


Was the file written on windows? Maybe you need to reformat the carriage return/new line to mac os x. try running the file through something like dos2unix on the command line. Could also be a bom you're not seeing.

文件是写在Windows上的吗?也许您需要将回车/换行重新格式化为mac os x。尝试在命令行上运行dos2unix之类的文件。也可能是你没见过的bom。

#4


My guess is that there's some hidden character that might have been accidentally saved in the file. Try re-saving the CSS file, or re-typing the first line and then re-saving it.

我的猜测是,有一些隐藏的角色可能被意外保存在文件中。尝试重新保存CSS文件,或重新键入第一行,然后重新保存它。

#5


If you're here from Google and working with local html, note that Firefox blocks requests for external CSS that use the file:// protocol because it's technically a cross-origin request.

如果您来自Google并使用本地html,请注意Firefox会阻止使用file://协议的外部CSS请求,因为它在技术上是一个跨源请求。

A quick fix is to serve the directory that contains your site to localhost over http://. If you have the python interpreter installed, you can do this very easily:

快速解决方法是通过http://将包含您站点的目录提供给localhost。如果安装了python解释器,则可以非常轻松地执行此操作:

python3 -m http.server 8080

Then access localhost through your browser:

然后通过浏览器访问localhost:

firefox localhost:8080

You can replace 8080 with any other port.

您可以将8080替换为任何其他端口。

#1


It's giving you the error on the first character in the file, which is a 'd', which rules out things like "hidden" special characters to me. I'd guess that firefox isn't able to open the file locally for whatever reason, or that the file was accidentally saved with an encoding that, although it displays fine in the dialog box, doesn't parse normally. Perhaps it's saved as Unicode by mistake?

它给你错误的文件中的第一个字符,这是一个'd',它排除了像我这样的“隐藏”特殊字符之类的东西。我猜想firefox无论出于何种原因都无法在本地打开文件,或者文件意外地保存了一个编码,尽管它在对话框中显示正常,但是没有正常解析。也许它被错误地保存为Unicode?

If you could link us to the actual file it would help, since your syntax (despite the markup not being exactly valid, but I don't think that's it) is perfect in the .css file you pasted in.

如果您可以将我们链接到实际文件,那将会有所帮助,因为您的语法(尽管标记不完全有效,但我认为不是这样)在您粘贴的.css文件中是完美的。

#2


The answer turned out to be "Turn off extensions (it was YSlow)" as suggested in the comments.

根据评论中的建议,答案结果是“关闭扩展(它是YSlow)”。

#3


Was the file written on windows? Maybe you need to reformat the carriage return/new line to mac os x. try running the file through something like dos2unix on the command line. Could also be a bom you're not seeing.

文件是写在Windows上的吗?也许您需要将回车/换行重新格式化为mac os x。尝试在命令行上运行dos2unix之类的文件。也可能是你没见过的bom。

#4


My guess is that there's some hidden character that might have been accidentally saved in the file. Try re-saving the CSS file, or re-typing the first line and then re-saving it.

我的猜测是,有一些隐藏的角色可能被意外保存在文件中。尝试重新保存CSS文件,或重新键入第一行,然后重新保存它。

#5


If you're here from Google and working with local html, note that Firefox blocks requests for external CSS that use the file:// protocol because it's technically a cross-origin request.

如果您来自Google并使用本地html,请注意Firefox会阻止使用file://协议的外部CSS请求,因为它在技术上是一个跨源请求。

A quick fix is to serve the directory that contains your site to localhost over http://. If you have the python interpreter installed, you can do this very easily:

快速解决方法是通过http://将包含您站点的目录提供给localhost。如果安装了python解释器,则可以非常轻松地执行此操作:

python3 -m http.server 8080

Then access localhost through your browser:

然后通过浏览器访问localhost:

firefox localhost:8080

You can replace 8080 with any other port.

您可以将8080替换为任何其他端口。