Html 页面显示代码未呈现

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

Page shows code not rendering

html

提问by Stella

enter image description hereI know this is simple question, but i am fighting with it for few hrs, so its better to ask in forum to get help quickly. I have added the following simple html snippet in a TextEdit program and saved the file as webpage(.html). When I run this file in any browser, like safari, chrome or firefox, it shows the same code there instead of rendering this as web page.

在此处输入图片说明我知道这是一个简单的问题,但我已经与它斗争了几个小时,所以最好在论坛上询问以快速获得帮助。我在 TextEdit 程序中添加了以下简单的 html 片段并将文件保存为网页(.html)。当我在任何浏览器(如 safari、chrome 或 firefox)中运行此文件时,它会在那里显示相同的代码,而不是将其呈现为网页。

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

Could someone help me to show this as real web page rather than source code showing?

有人可以帮助我将其显示为真实的网页而不是源代码显示吗?

采纳答案by Xenopathic

It is likely thatTextEdit hasformatted your text, since by saving it as a Web Document it thinks that you have typed up the web page how you want it displayed, with all formatting, instead of raw HTML code. Try to save the document as raw text, then change the extension manually from whatever it is (probably .txt) to .html. For a more permanent solution, it is advisable to use a non-formatting text editor when coding.

很可能TextEdit已经格式化了您的文本,因为通过将其保存为 Web 文档,它认为您已经按照您希望的方式输入了网页,并带有所有格式,而不是原始 HTML 代码。尝试将文档保存为原始文本,然后手动将扩展名从任何内容(可能.txt)更改为.html. 对于更持久的解决方案,建议在编码时使用非格式化文本编辑器。

EDIT: This is what Apple have to say: http://support.apple.com/kb/ta20406

编辑:这就是苹果必须说的:http: //support.apple.com/kb/ta20406

回答by Grigoreas P.

If you have access to the server scripts creating the page, then check if somewhere the http headers are being changed by that code. The browser needs to receive a header like that

如果您有权访问创建页面的服务器脚本,请检查该代码是否在某处更改了 http 标头。浏览器需要接收这样的标头

Content-Type: text/html
[example in PHP: header(Content-Type: text/html);]

in order to render html properly. If this header is changed, then the browser won't be able to interpret it as html.

为了正确呈现html。如果此标头更改,则浏览器将无法将其解释为 html。

回答by Aditya Singh

The solution to your problem is simple. Just open TextEdit and go to preferences. Just tick the box which says"display html files as html code instead of formatted text". Your problem will be solved. :)

解决您的问题很简单。只需打开 TextEdit 并转到首选项。只需勾选“将 html 文件显示为 html 代码而不是格式化文本”的框。您的问题将得到解决。:)

回答by Ben B

You have saved the text you pasted in as HTML content, in the HTML editor. Instead, you should try to paste the text in the codeview, not the editorview.

您已在 HTML 编辑器中将粘贴的文本保存为 HTML内容。相反,您应该尝试将文本粘贴到代码视图中,而不是编辑器视图中。