HTML DOCTYPE 语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3793218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML DOCTYPE Syntax error
提问by aneuryzm
I get the following syntax error in Firebug and I don't get what's it:
我在 Firebug 中收到以下语法错误,但我不明白是什么:
> syntax error [Break on this error]
> <!DOCTYPE html PUBLIC "-//W3C//DTDXHT...org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n
Is it because of the final "\n" at the end ?
是因为最后的“\n”吗?
thanks
谢谢
ps. I've just realized if I remove all scripts, I don't get that error. For example, if I remove these lines, I don't get it. If I add another script I get it again, so it doesn't depend on the script itself.
附:我刚刚意识到如果我删除所有脚本,我不会收到那个错误。例如,如果我删除这些行,我就不会明白。如果我添加另一个脚本,我会再次得到它,所以它不依赖于脚本本身。
<script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/main.js"></script>
CODE:
代码:
<?php
// $Id: page.tpl.php,v 1.28.2.1 2009/04/30 00:13:31 goba Exp $
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language ?>" xml:lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
<head>
<?php print $head ?>
<title><?php print $head_title ?></title>
<?php print $styles ?>
<?php print $scripts ?>
<script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/main.js"></script>
<!--<script type="text/JavaScript" src="<?php echo $base_url; ?>sites/all/themes/bluemarine/js/griddy-min.js"></script>
-->
</head>
<body>...
回答by Darin Dimitrov
Ryan Rampersad, blogged about this issue stating
Ryan Rampersad,关于这个问题的博客指出
The error comes from Firebug. The break on this error isn't a part of the error but it is in the firebug copy dump....
错误来自 Firebug。此错误的中断不是错误的一部分,但它在 firebug 副本转储中....
syntax error [Break on this error] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML…3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
syntax error [Break on this error] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML…3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
The way I encountered this error was that I forgot to specify a src attribute value for my script tag!
我遇到这个错误的方式是我忘记为我的脚本标签指定一个 src 属性值!
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
Here is the blog post.
这是博客文章。
回答by Quentin
I suspect that you have a <script>
pointing to a URL that returns an HTML document (possibly it should be coming with a 404 response but isn't)
我怀疑您<script>
指向一个返回 HTML 文档的 URL(可能它应该带有 404 响应,但不是)
回答by Christoforos
I had the same issue. For me the problem was that I loaded a script file that pointed to nowhere or to be more precise it pointed to my domain root. The script declaration was <script src="http://mydomain/" type="text/javascript" />
. What was happening was that the script was loading my home page. The first character of a home page is "<" because all html pages start with "<!DOCTYPE ......"
. Well this is a syntax error so and that was it. Once I eliminated <script src="http://mydomain/" type="text/javascript" />
everything was ok. I hope I helped you.
EDIT:In short, check your src
pointers on your Javascript links to be sure they point at the correct files.
我遇到过同样的问题。对我来说,问题是我加载了一个指向任何地方的脚本文件,或者更准确地说,它指向我的域根。脚本声明是<script src="http://mydomain/" type="text/javascript" />
. 发生的事情是脚本正在加载我的主页。主页的第一个字符是“<”,因为所有的 html 页面都以"<!DOCTYPE ......"
. 好吧,这是一个语法错误,仅此而已。一旦我消除了<script src="http://mydomain/" type="text/javascript" />
一切就可以了。我希望我帮助了你。
编辑:简而言之,检查您src
的 Javascript 链接上的指针,以确保它们指向正确的文件。
回答by Atara
In my case, when I received such error, the cause was "un authorised access" to the JS file.
就我而言,当我收到此类错误时,原因是对 JS 文件的“未经授权的访问”。
To detect it, use FireBug, [HTML] tab: Try to expand each "script" node. one of these nodes contained the "401.html" page-content instead of the expected JS content.
要检测它,请使用 FireBug,[HTML] 选项卡:尝试展开每个“脚本”节点。这些节点之一包含“401.html”页面内容而不是预期的 JS 内容。
回答by Captain
I had the same problem. After trying many solution and searching about it, finally I got why I was getting that error.
我有同样的问题。在尝试了许多解决方案并对其进行了搜索之后,我终于明白了为什么会出现该错误。
I was getting that error because of invalid path in src attribute of script tag. Like I was adding script as below by simply dragging script on page from solution explorer in visual studio and I was getting error. My src attribute in script tag was src="~/js/jquery.min.js"
由于脚本标记的 src 属性中的路径无效,我收到了该错误。就像我通过简单地从 Visual Studio 中的解决方案资源管理器在页面上拖动脚本来添加如下脚本一样,我遇到了错误。我在脚本标签中的 src 属性是src="~/js/jquery.min.js"
And I found that I was not getting script on that page.
我发现我没有在该页面上获取脚本。
So I used below solution to load script on that page. src attribute in script tag src="../../js/jquery.min.js"
所以我使用以下解决方案在该页面上加载脚本。脚本标签中的 src 属性src="../../js/jquery.min.js"