where to place the javascript in html page

A

acord

Hi,

I m getting annoying display problem when placing javascript tags in a
html page. Should the javasscript tags placed at the beginning of a
html page before anything start? or placed between the <head></head>
tags? If I placed the script tags at the beginning of the html page, I
can have the Draggale Layer shown and movable by the mouse, but the
entired page will not read the style.css file (as I found the font
displayed very ugly); If I placed the script tags between the <head>
</head> tags, the Draggable Layer is movable, but the font are displayed
correctly.

eg.

<script language="JavaScript1.2">
Draw draggle layer...
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Eveready</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
....
</body>

The above java script placed at the start of the html page will make the
Draggable Layer moving fine, but the rest of the font dispalyed very ugly.

Thanks
A
 
A

acord

Hi,

I just found the following offending code causes the Draggable Layer not
moving:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

where should I place the above code in my html page?
I need to have that for a correct display of the font. But having it
will cause the box not movable. Without it, font is not display correctly.

A
 
M

marss

acord said:
where should I place the above code in my html page?
I need to have that for a correct display of the font. But having it
will cause the box not movable. Without it, font is not display correctly.

It would be a good thing to post as much as possible simplified example
that can reproduce problem.
 
D

David Trimboli

acord said:
Hi,

I m getting annoying display problem when placing javascript tags in
a html page. Should the javasscript tags placed at the beginning of
a html page before anything start? or placed between the
<head></head> tags? If I placed the script tags at the beginning of
the html page, I can have the Draggale Layer shown and movable by
the mouse, but the entired page will not read the style.css file (as
I found the font displayed very ugly); If I placed the script tags
between the <head> </head> tags, the Draggable Layer is movable, but
the font are displayed correctly.

eg.

<script language="JavaScript1.2">
Draw draggle layer...
</script>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Eveready</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>

<body>
...
</body>

The above java script placed at the start of the html page will make
the Draggable Layer moving fine, but the rest of the font dispalyed
very ugly.


The doctype declaration must be the first line in the document.

Where the script element goes depends on what's in the script and how
it's triggered. It must go in either the head or the body. We can't
tell you more without more information about the script.

David
Stardate 6203.1
 
R

RobG

acord said on 16/03/2006 12:19 AM AEST:
Hi,

I just found the following offending code causes the Draggable Layer not
moving:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

where should I place the above code in my html page?

The doctype affects features within the page. It must appear as the
first thing, before any HTML.

Don't use such an old doctype unless you have a very good reason, use a
strict doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

I need to have that for a correct display of the font. But having it
will cause the box not movable. Without it, font is not display correctly.

You are (probably) seeing the effect of the doctype - removing it causes
the browser to go into 'quirks mode' and anything is possible. *Always*
use a doctype.

<URL:http://www.quirksmode.org/css/quirksmode.html>


[...]
Script elements, of themselves, have no effect at all on display. Their
content might. Moving them to produce invalid HTML is not catered for
in specification.

Don't futz around until 'something works', find out why it's going wrong
and fix the problem at the source. Asking your question here was a good
start.


Script elements can be placed anywhere in the head or body of a
document, the tags must be properly nested.


You are seeing the results of the browser's attempts at error correction
of your invalid HTML - garbage in, garbage out.


Do not use the language attribute - especially that one. Use type as
it's required:


The script element can't appear before the doctype, or the opening HTML
or HEAD tags (if present).


Who knows what effect invalid HTML should have on a web page? Start
with a strict DTD and valid HTML and go from there.

<URL:http://validator.w3.org/>
 
T

Thomas 'PointedEars' Lahn

RobG said:
acord said on 16/03/2006 12:19 AM AEST:

The doctype affects features within the page. It must appear as the
first thing, before any HTML.

s/doctype/DOCTYPE declaration/
s/any/any other/
s/\.$/ to trigger DOCTYPE switching./


PointedEars
 

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

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top