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

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

Browser shows plain text instead of HTML in mac

htmlmacosfirefoxbrowser

提问by Navid777

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! what's the problem?

我写了它并用名称将它保存在我的桌面上hello.html,但是当我用 firefox 或 safari 打开这个文件时,浏览器会显示整个文本(包括<html>和所有文本),而不是只显示my first heading! 有什么问题?

回答by Navid777

The problem was that I wrote the HTML document with "Text Edit" application, and it saved the file with .rtfextension, that is not plain text, so changing the name of file to hello.htmldidn'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->preferencesand tick the plain textat 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

回答by Quentin

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。

回答by Venu Gopal Tewari

Download install "TextWrangler" (for mac) paste your html content to a new file in it and save with .html link. Dont use TextEdit.

下载安装“TextWrangler”(Mac 版),将您的 html 内容粘贴到其中的新文件中,并使用 .html 链接保存。不要使用文本编辑。

回答by johnD

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. That's what happened to me.

如果您使用基本文本编辑器(如终端中的 nano)打开文件,您可能会看到在基本 HTML 代码中添加了许多额外的行。这就是发生在我身上的事情。

I removed all the lines except what I wanted and it finally rendered correctly.

我删除了除我想要的之外的所有行,它最终正确呈现。

回答by Kateryna Azarova

I've had the same issue in 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.

我在 TextEdit 中遇到了同样的问题。解决方案是 - 转到“格式”,然后“制作纯文本”。保存文档并在浏览器中再次打开它。它在我的情况下有效。希望它也对你有用。

回答by Paul Slocum

I found that the parent folder on my web server contained an old .htaccessfile that was causing HTML files to display as plain text. Renaming/reworking the .htaccessfile or just moving my HTML file to another folder fixed the issue.

我发现 Web 服务器上的父文件夹包含一个旧.htaccess文件,该文件导致 HTML 文件显示为纯文本。重命名/修改.htaccess文件或只是将我的 HTML 文件移动到另一个文件夹解决了这个问题。

回答by Dimitri Kouvdis

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 结尾