onmousedown hangs in Mozilla Help!

G

Gary Mayor

Hi,
I'm trying to make it so when I click a image it prints out the image
again and a load of other stuff. So far i've got this far.

<html>
<head>
<script language="JavaScript" type="">
document.onmousedown = onmousedown;
function onmousedown(e)
{
document.writeln("hello");
}
</script>
</head>
<body bgcolor="FFFFFF">

<img border="1" src="iecadaptor.jpg">

</body>
</html>

but in Mozilla it prints out hello then hangs looking like it's doing
something then I have to press back. In Explorer it works doesn't hang.
Any ideas anyone why it's hanging in mozilla(linux)?
Also if I change the document.writeln("hello"); to

document.writeln("<img border="1" src="iecadaptor.jpg">");

it doesn't print out an image just hangs in mozilla. Any ideas?

Ideally I would like it so document.writeln doesn't have to reload to a
new page and just uses a layer using <div stuff but that's next.

Help anyone please

Thanks

Gary
 
M

Martin Honnen

Gary said:
I'm trying to make it so when I click a image it prints out the image
again and a load of other stuff. So far i've got this far.

<html>
<head>
<script language="JavaScript" type="">
document.onmousedown = onmousedown;
function onmousedown(e)
{
document.writeln("hello");
}
</script>
</head>
<body bgcolor="FFFFFF">

<img border="1" src="iecadaptor.jpg">

</body>
</html>

but in Mozilla it prints out hello then hangs

Well it is hanging there waiting for further document.write calls or a
document.close() call.
 
G

Gary Mayor

Martin said:
Well it is hanging there waiting for further document.write calls or a
document.close() call.

Thank you very much the document.close() works a treat. Now I can figure
out the rest.

Cheers
 
M

Michael Winter

<script language="JavaScript" type="">

Don't do that. The type attribute should be used to specify the scripting
language, not language (it is deprecated).

<script type="text/javascript">

is the correct way to write the tag (with optional src and defer
attributes).

Mike
 
R

Ren Bruns

A function cannot be named "onmousedown" or "onMouseDown" or anything
that is already predefined in Javascript (that would rule out "write",
"writeln", "replace", "length", "for", "if", etc..).
document.writeln("<img border="1" src="iecadaptor.jpg">");

The quotations need to be "escaped," that is, it needs to be:
document.writeln("<img border=\"1\" src=\"iecadaptor.jpg\">");

If the quotes were not escaped, then it would be read as "<img
border=" only and then an error would come saying something how the
string wasn't concatenated properly.
 
L

Lasse Reichstein Nielsen

A function cannot be named "onmousedown" or "onMouseDown" or anything
that is already predefined in Javascript (that would rule out "write",
"writeln", "replace", "length", "for", "if", etc..).

Sure it can. "for" and "if" are keywords, and cannot be used for
identifiers. The remaining are perfectly good names for functions
(although one should be careful when using them, since they can
conflict with other uses of the identifier).

The following is perfectly legal and works (tested in IE6, Opera 7,
Moz FB, and Netscape 4):

<script type="text/javascript">
function onMouseMove() {
return onmousemove();
}
function onmousemove() {
return writeln();
}
function writeln() {
return write();
}
function write() {
return replace();
}
function replace() {
return length();
}
function length() {
return 42;
}
alert(onMouseMove());
</script>


/L 'please don't top post'
 
T

Thomas 'PointedEars' Lahn

Ren said:
A function cannot be named "onmousedown" or "onMouseDown" or anything
that is already predefined in Javascript (that would rule out "write",
"writeln", "replace", "length", "for", "if", etc..).

Nonsense. Firstly, "onMouseDown" is not defined in any common DOM.
Secondly, a user-defined function *should* not have one of the mentioned
identifiers (where "for" and "if" make an exception, see below).
Depending on the used DOM, it nevertheless can and would thus overwrite
the intrinsic method. Sometimes this is desired, e.g., when writing
script that blocks popups. Thirdly, no user-defined token, including
method identifiers, may be a reserved word, like "for" and "if".
The quotations need to be "escaped," that is, it needs to be:
document.writeln("<img border=\"1\" src=\"iecadaptor.jpg\">");

No, it needs not to be escaped. Fortunately, ECMAScript
and implementations allow <'> for string delimiter:

document.writeln(' said:
[Top post]

Please do not do that, you are wasting precious resources.


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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top