简体   繁体   English

浏览器在 mac 中显示纯文本而不是 HTML

[英]Browser shows plain text instead of HTML in mac

I want to write an html document like this :我想写一个这样的html文档:

<html>
<body>

<h1>My First Heading</h1>

</body>
</html>

I wrote it and saved it in my desktop with the name hello.html , but when I open this file with firefox or safari, the browser shows the whole text (including <html> and all of the texts) instead of only showing my first heading !我写了它并以hello.html名称将它保存在我的桌面上,但是当我用 firefox 或 safari 打开这个文件时,浏览器会显示整个文本(包括<html>和所有文本),而不是只显示my first heading what's the problem?有什么问题?

The problem was that I wrote the HTML document with "Text Edit" application, and it saved the file with .rtf extension, that is not plain text, so changing the name of file to hello.html didn't change anything.问题是我用“文本编辑”应用程序编写了 HTML 文档,它以.rtf扩展名保存了文件,这不是纯文本,因此将文件名更改为hello.html并没有改变任何内容。

there are two ways to fix this problem:有两种方法可以解决此问题:

1) if you insist on using "Text Edit" you should go to text edit->preferences and tick the plain text at top of the page, then when you save something, it is saved as plain text 1)如果你坚持使用“文本编辑”,你应该去text edit->preferences并勾选页面顶部的plain text ,然后当你保存一些东西时,它被保存为纯文本

2) you can use some text editor, like lime edit 2)你可以使用一些文本编辑器,比如lime edit

The most likely reason is that you used a WYSIWYG editor and saved the document as HTML.最可能的原因是您使用了 WYSIWYG 编辑器并将文档保存为 HTML。

This created an HTML representation of the HTML source code you typed.这创建了您键入的 HTML 源代码的 HTML 表示。

Use a text editor instead.请改用文本编辑器。 I'm fond of Sublime Edit 2.我喜欢 Sublime Edit 2。

Download install "TextWrangler" (for mac) paste your html content to a new file in it and save with .html link.下载安装“TextWrangler”(Mac 版),将您的 html 内容粘贴到其中的新文件中,并使用 .html 链接保存。 Dont use TextEdit.不要使用文本编辑。

If you open the file using a basic text editor (like nano from the terminal), you'll probably see there's a lot of additional lines added to your basic HTML code.如果您使用基本文本编辑器(如终端中的 nano)打开文件,您可能会看到在基本 HTML 代码中添加了许多额外的行。 That's what happened to me.这就是发生在我身上的事情。

I removed all the lines except what I wanted and it finally rendered correctly.我删除了除我想要的之外的所有行,它最终正确呈现。

I've had the same issue in TextEdit.我在 TextEdit 中遇到了同样的问题。 The resolution is - go to "Format", then "Make plain text".解决方案是 - 转到“格式”,然后“制作纯文本”。 Save the document and open it again in browser.保存文档并在浏览器中再次打开它。 It had worked in my case.它在我的情况下有效。 Hope it will work for you too.希望它也对你有用。

I found that the parent folder on my web server contained an old .htaccess file that was causing HTML files to display as plain text.我发现我的 Web 服务器上的父文件夹包含一个旧的.htaccess文件,该文件导致 HTML 文件显示为纯文本。 Renaming/reworking the .htaccess file or just moving my HTML file to another folder fixed the issue.重命名/修改.htaccess文件或将我的 HTML 文件移动到另一个文件夹解决了这个问题。

I have same issue.我有同样的问题。 I am using TextEdit.我正在使用文本编辑。 Issue was fixed by following the change: text edit->preferences>New document>Fromat>plain text (not Rich text).通过以下更改修复了问题:文本编辑->首选项>新文档>Fromat>纯文本(非富文本)。

Use a text editor such as Dreamweaver, Sublime使用文本编辑器,例如 Dreamweaver、Sublime

Sublime http://www.sublimetext.com/2崇高的http://www.sublimetext.com/2

and ensure your file ends in .html not .txt并确保您的文件以 .html 而不是 .txt 结尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM