calling external javascript file

K

korund

<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function init() {
alert('Message 1');
alert(''Message 2');
alert(''Message 3');
alert('text, etc');
var w = window.open('http://www.url.com');

}

window.onload = init;
</script>
</head>
<body>
</body>
</html>

that's just example.
I want use script as external file (script.js), and call it from html
page. Should I place reference to jscript in body tags, or place
reference in head tags?
<body>
<script src=script.js></script>
.....
 
R

Randy Webb

(e-mail address removed) said the following on 4/24/2006 10:25 AM:
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function init() {
alert('Message 1');
alert(''Message 2');
alert(''Message 3');
alert('text, etc');
var w = window.open('http://www.url.com');

}

window.onload = init;
</script>
</head>
<body>
</body>
</html>

that's just example.
I want use script as external file (script.js), and call it from html
page. Should I place reference to jscript in body tags, or place
reference in head tags?

If you place the script tag in the head tag (or body tag) then it will
be a horrendous disaster and your script won't get executed. Now, if you
place them in the Head Section (or Body Section) then either place is
fine but the Head Section is preferred for some oddball reason.
 
K

korund

(e-mail address removed) said the following on 4/24/2006 10:25 AM:
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function init() {
alert('Message 1');
alert(''Message 2');
alert(''Message 3');
alert('text, etc');
var w = window.open('http://www.url.com');

}

window.onload = init;
</script>
</head>
<body>
</body>
</html>

that's just example.
I want use script as external file (script.js), and call it from html
page. Should I place reference to jscript in body tags, or place
reference in head tags?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top