为什么我的网络浏览器上没有 html 呈现?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6758706/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:38:56  来源:igfitidea点击:

Why isn't html rendering on my web browser?

htmlrenderinghtml-rendering

提问by Chucky

It just appears like this in Google Chrome:

它在谷歌浏览器中看起来像这样:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>

Why isn't it transforming as expected?

为什么它没有按预期转变?

Edit: Yes the file does have an .html filename. I'm not sure it should need a header yet according to a tutorial I'm using which says that it should render correctly without one? All new to this so I'm unsure.

编辑:是的,该文件确实有一个 .html 文件名。根据我正在使用的教程,我不确定它是否应该需要一个标题,该教程说它应该在没有标题的情况下正确呈现?这一切都是新的,所以我不确定。

Edit: When I open it with textedit, I get this:

编辑:当我用 textedit 打开它时,我得到这个:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="1038.35">
  <style type="text/css">
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
  </style>
</head>
<body>
<p class="p1">&lt;html&gt;</p>
<p class="p1">&lt;head&gt;</p>
<p class="p1">&lt;title&gt;Hello World!&lt;/title&gt;</p>
<p class="p1">&lt;/head&gt;</p>
<p class="p1">&lt;body&gt;</p>
<p class="p1">&lt;h1 align="center"&gt;Hello World!&lt;br/&gt;Welcome to My Web Server.&lt;/h1&gt;</p>
<p class="p1">&lt;/body&gt;</p>
<p class="p1">&lt;/html&gt;</p>
</body>
</html>

I don't remember saving it like this at all.

我根本不记得像这样保存它。

回答by inspite

How did you create the web page? It is possible that the editor that you used converted the html so that it shows "<" instead of rendering them

你是如何创建网页的?您使用的编辑器可能转换了 html,使其显示“<”而不是呈现它们

Open the file in notepad, check that the contents are:

在记事本中打开文件,检查内容是否为:

<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1 align="center">Hello World!<br/>Welcome to My Web Server.</h1>
</body>
</html>

and not

并不是

&lt;html&gt;
......
&lt;/html&gt;

make sure you save your file with a .html extension

确保使用 .html 扩展名保存文件

回答by Mr Moose

It should be rendered by the browser, not the webserver. Check the HTTP headers "Content-Type". It should read something like "Content-Type: text/html; charset=utf-8".

它应该由浏览器呈现,而不是网络服务器。检查 HTTP 标头“Content-Type”。它应该是类似“Content-Type: text/html; charset=utf-8”的内容。

Given your using Chrome, load up developer tools using the following steps;

鉴于您使用 Chrome,请使用以下步骤加载开发人员工具;

  1. Right click the page -> Choose "Inspect Element"
  2. Go to the network tab
  3. Load the page your trying to inspect
  4. Pick the URL of the page for which you want to inspect headers etc
  1. 右键单击页面 -> 选择“检查元素”
  2. 转到网络选项卡
  3. 加载您尝试检查的页面
  4. 选择要检查标题等的页面的 URL

回答by Michael Borgwardt

From the file content you posted contains the explanation:

从您发布的文件内容中包含解释:

<meta name="Generator" content="Cocoa HTML Writer">

Basically, your text editor thought you wanted to convertthe "text" you had entered to a webpage. So it saved it as a webpage that displays exactly what you have entered.

基本上,您的文本编辑器认为您想输入的“文本”转换为网页。所以它把它保存为一个网页,显示你输入的内容。

How did you save the file? If you used anything that says "convert" or "export" to HTML, that's the culprit. Just use the regular "save" option. And if that doesn't work: get a better editor, one that doesn't try to be smarter than you.

你是怎么保存文件的?如果您使用任何表示“转换”或“导出”为 HTML 的内容,那就是罪魁祸首。只需使用常规的“保存”选项即可。如果这不起作用:找一个更好的编辑器,一个不会试图比你更聪明的编辑器。