为提升您的使用体验,本站正在维护,部分功能暂时无法使用。如果本站文章无法解决您的问题,您想要向社区提问的话,请到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 提问,我们的支持社区将会很快回复您的疑问。

搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

Opening html code rather than web page

  • 13 个回答
  • 10 人有此问题
  • 1 次查看
  • 最后回复者为 serky100

more options

I am using Firefox 8. I have a simple html file called test.html stored locally.

When I double click on the file it open in Firefox as html code rather than the web page. What am I doing wrong?

I am using Firefox 8. I have a simple html file called test.html stored locally. When I double click on the file it open in Firefox as html code rather than the web page. What am I doing wrong?

被采纳的解决方案

I have resolved the issue. The file was working correctly. I made the mistake of coding html in a text file and then saving the file as html. This resulted in the html tags being coded a second time with html. Hence being able to view html tags in the web page.

定位到答案原位置 👍 0

所有回复 (13)

more options

Are you loading that file via a local server via the http:// protocol or as a file via the file:///protocol?

If it is via a server then make sure that the file is send as text/html

more options

I don't know which protocol is being used. How do I find out?

I am not using a server - just my own Mac.

more options

Which URL so you see in the location (address) bar if you open the file? If it starts with http:// then it is opened as a web page and not as a file.

Also make sure that the file doesn't have a .txt file extension i.e. test.html.txt that is possibly added if you save a file in a text editor.

more options

Hello

after replying to you, I looked further than my nose and noticed that the URL starts with file:/// The file suffix is definitely html (yes it was edited in text edit but I did a 'save as' html).

What determines what protocol is being used? Is there a setting that I need to change? I thought that the Mac would recognise that it's a html file (from the file suffix) and load as a web page into browser.

I have not activated the web server on my mac. Is this the problem?

more options

Firefox should automatically display .html files rendered and not as text files even if loaded with the file protocol.

Can you post the first few lines of that file?

more options

It's very simple as I'm just starting to learn. I copied it from a site to test the html.

<html>

<head>
</head>

<body>

<h2>My first webpage!</h2>

</body>
</html>

由cor-el于修改

more options

I just noticed that my reply above converted the html to web. Useful!

I copied it again and removed the first and end bracket for the html tag.

html>

<head> </head>

<body>

My first webpage!

</body>

more options

So, there is nothing wrong with the file.

What do you see in Tools > Page Info > General ?

more options

I have added a screenshot below to show Tools > Page Info > General

Does this explain the problem?

more options

That still doesn't show that there is a problem: opened as text/html and rendered in Standards compliant mode.


Start Firefox in Diagnose Firefox issues using Troubleshoot Mode to check if one of the extensions or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).

more options

I tried this (Firefox looks weird as I have customised it to some degree!)

It didn't fix the problem. I double clicked on test.html and it open showing the html tags and the file:/// protocol.

I am currently considering changing career to website design/development but am wondering if this is feasible when I can't even get a 6 line html file to work!!

more options

I also tried it in Safari 5.1.1. The same problem occurs. Is this suggesting a Mac problem rather than Firefox?

more options

选择的解决方案

I have resolved the issue. The file was working correctly. I made the mistake of coding html in a text file and then saving the file as html. This resulted in the html tags being coded a second time with html. Hence being able to view html tags in the web page.