Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open in browser but only get code

Status
Not open for further replies.

Kennrosie

Programmer
Nov 30, 2005
3
US
This is my first try at java script:

I put the following into notepad and saved as test.js:

<html>
<body>

<script type="text/javascript">
document.write("Hello World!")
</script>

</body>
</html>


When I try to open this file in my browser, I only get this code back and not "Hello World"

 
you only need to save a javascript file as .js if the ONLY CODE it has in it is javascript.

the following scenarios produce the same result:

test.html
Code:
<html>
<head>
<script type="text/javascript"><!--
function doSomething() {
    document.write("Hello World!");
}
//--></script>
</head>
<body>

<script type="text/javascript">
doSomething();
</script>

</body>
</html>

OR



test.html
Code:
<html>
<head>
<script type="text/javascript" src="test.js"></script>
</head>
<body>

<script type="text/javascript">
doSomething();
</script>

</body>
</html>

test.js
Code:
function doSomething() {
    document.write("Hello World!");
}


hope this helps...

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
answered my own question.... I used .htm extension instead of .js and it works
 
If you check the first answer from cLFlaVA, I think you'll find that had already been suggested...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top