/    Sign up×
Community /Pin to ProfileBookmark

Javascript doesn’t interpret on my Mac browsers

This is dirt simple javascript and it works on a pc using notepad as an editor on IE but I can’t open it (I did save it as html) with Safari or Firefox or IE using TextEdit on a G5 Mac! When I open it in the browser it simply displays the code instead of interpreting it. I have javascript enabled in Safari. Any ideas what could cause this? ?

<HTML>
<BODY>
<SCRIPT Language=”JavaScript”>
<!-
document.write(“This text was written with JavaScript!”);
//–>
</SCRIPT>
</BODY>
</HTML>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallOct 07.2007 — The language attribute is deprecated.

You have the document.write statement commented out.

document.write should work before the page is loaded but only if the page is served as HTML. It will not work after the page loads or if the page is served as anything other than HTML.

You are missing a DOCTYPE at the top of the source.

If it is displaying as text instead of HTML then you must be serving it as text instead of as HTML. Only local files served on Windows use the file extension to work out how to serve them. Other operating systems and pages from the web use the MIME type defined for the page to determine what it is.
Copy linkTweet thisAlerts:
@thepopomanauthorOct 08.2007 — I am still stuck. Sounds like you are saying that my page is being served as text instead of HTML. I assumed when you say "served as" you mean "interpreted as" or "processed as". Where/how do I change the MEME type to make it HTML instead of text? If you don't set this inside the file then I have no idea how to save it differently using my simple editor. I saved the file as HTML in Text Edit. The other Save As options are RTF, Word format and Word XML format in addition to saving it as HTML.

I tried this XHTML (no javascript) from the DOM Scripting book by Jeremy Keith but it still doesn't interpret:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

"http://www.w3.org/TR/xhtml11/DTD/xhtml11dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Shopping list</title>

</head>

<body>

<h1>What to buy</h1>

<p title="a gentle reminder">Don't forget to buy this stuff.</p>

<ul id="purchases">

<li>A tin of beans</li>

<li>Cheese</li>

<li>Milk</li>

</ul>

</body>

</html>
Copy linkTweet thisAlerts:
@thepopomanauthorOct 09.2007 — I found out I was screwing the file up by saving it as HTML when I really wanted to save it as Ascii text.
×

Success!

Help @thepopoman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...