Stella
Stella

Reputation: 1866

Page shows code not rendering

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.

<!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?

Upvotes: 12

Views: 96436

Answers (5)

harishanth raveendren
harishanth raveendren

Reputation: 614

In case any of you have already created the file and not sure how to proceed, open the file in TextEdit. Go to Format -> Make plan text. Then save and close the file. Then open the file location in finder and rename to .html and this will convert the file appropriately.

Upvotes: 1

Ben Butterworth
Ben Butterworth

Reputation: 29038

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 code view, not the editor view.

Upvotes: 0

Grigoreas P.
Grigoreas P.

Reputation: 2472

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

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.

Upvotes: 13

Aditya Singh
Aditya Singh

Reputation: 41

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. :)

Upvotes: 4

Robin McCorkell
Robin McCorkell

Reputation: 774

It is likely that TextEdit has formatted 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.

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

Upvotes: 10

Related Questions