当页面采用 UTF-8 编码时,如何消除服务器端包含周围的空格?
我有一个通过 IIS 7.5 运行的站点,其页面以 UTF-8 编码(请注意,如果我恢复为 ASCII,则不会出现以下问题)。我有一个 Main.html 页面,其中包含页眉和页脚内容。当这些文件通过 SSI 包含时,空格会被注入到正文中并强制我的页面内容下降。如果我将这些文件合并在一起,这个问题就会消失。 这个问题和我的一样,但答案对我不起作用。
考虑以下 4 个页面:
SSI.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Humble Site</title>
<!--#include file="SSIIncludes.html" -->
</head>
<body>
<form id="Form1" runat="server" onsubmit="return false;">
<!--#include file="SSIHeader.html" -->
<div>Here's my content</div>
<script type="text/javascript">
//do some work
</script>
<!--#include file="SSIFooter.html" -->
</form>
</body>
</html>
SSIInincludes.html:
<link rel="stylesheet" type="text/css" href="js/jquery.ui.all.css" />
<script type="text/javascript">
var debug = false;
if (debug) {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/jquery-ui.js"><\/script>');
} else {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"><\/script>');
}
</script>
SSIHeader.html:
<div>
<div>
<div>
Something's in a Header!
</div>
SSIFooter.html:
<div>
Have a Footer!
</div>
</div>
</div>
<br />
<br />
<br />
当我查看该页面时,我在第一个 div 文本之前看到一大块空白(如浏览器中呈现的那样)。探索浏览器中的源代码会发现:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Humble Site</title>
</head>
<body>
""
<link rel="stylesheet" type="text/css" href="js/jquery.ui.all.css">
<script type="text/javascript">
var debug = false;
if (debug) {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/jquery-ui.js"><\/script>');
} else {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"><\/script>');
}
</script>
<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"></script>
<form id="Form1" runat="server" onsubmit="return false;">
"
"
<div class="OwnerOfAllPlaces">
<div id="OuterPlace" class="OuterPlace">
<div>
Something's in a Header!
</div>
<div>Here's my content</div>
<script type="text/javascript">
//do some work
</script>
"
"
<div>
Have a Footer!
</div>
</div>
</div>
<br>
<br>
<br>
</form>
</body></html>
我怎样才能摆脱包含点处的这些“”“”块?
I have a site running through IIS 7.5, whose pages are encoded in UTF-8 (note I do not have the following problem if I revert to ASCII). I have a Main.html page which includes a header and footer content. When these files are included via SSI, whitespace is injected into the body and forces my page content down. If I combine the files together, this issue goes away. This question is the same as mine, but the answer does not work for me.
Consider the following 4 pages:
SSI.html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Humble Site</title>
<!--#include file="SSIIncludes.html" -->
</head>
<body>
<form id="Form1" runat="server" onsubmit="return false;">
<!--#include file="SSIHeader.html" -->
<div>Here's my content</div>
<script type="text/javascript">
//do some work
</script>
<!--#include file="SSIFooter.html" -->
</form>
</body>
</html>
SSIIncludes.html:
<link rel="stylesheet" type="text/css" href="js/jquery.ui.all.css" />
<script type="text/javascript">
var debug = false;
if (debug) {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/jquery-ui.js"><\/script>');
} else {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"><\/script>');
}
</script>
SSIHeader.html:
<div>
<div>
<div>
Something's in a Header!
</div>
SSIFooter.html:
<div>
Have a Footer!
</div>
</div>
</div>
<br />
<br />
<br />
When I view the page, I see a large block of whitespace (as rendered in the browser) immediately before my first div text. Exploring the source in-browser reveals:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Humble Site</title>
</head>
<body>
""
<link rel="stylesheet" type="text/css" href="js/jquery.ui.all.css">
<script type="text/javascript">
var debug = false;
if (debug) {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/jquery-ui.js"><\/script>');
} else {
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"><\/script>');
document.write('<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"><\/script>');
}
</script>
<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="js/thirdparty/jquery/core/jquery-ui-1.8.12/ui/minified/jquery-ui.min.js"></script>
<form id="Form1" runat="server" onsubmit="return false;">
"
"
<div class="OwnerOfAllPlaces">
<div id="OuterPlace" class="OuterPlace">
<div>
Something's in a Header!
</div>
<div>Here's my content</div>
<script type="text/javascript">
//do some work
</script>
"
"
<div>
Have a Footer!
</div>
</div>
</div>
<br>
<br>
<br>
</form>
</body></html>
How can I rid myself of these "" " " blocks at my include points?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能文件保存为 UTF-8 + BOM。
BOM = 字节顺序标记
BOM 基本上只是添加在文档开头的三个(不可见)字符。 (至少在 UTF-8 中)
您不希望它出现在您的文档中。
某些文本编辑器允许您选择将文件另存为不带 BOM 的 UTF-8。
我使用 EditPlus 来实现此目的,但其他也可能有效。
Probably the files are saved as UTF-8 + BOM.
BOM = Byte Order Mark
The BOM basically are just three (not visible) characters which is added at the start of a document. (At least in UTF-8)
You do not want it in your documents.
Some text-editors give you the option to save a file as UTF-8 without BOM.
I use EditPlus for this, but other might also work.