473,390 Members | 936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

onmousedown event causing body onload event to fire

Hi,

I am wanting to capture an onmousedown event without firing the body tags
onload event.

Also, if anyone could explain why this happens that would be excellent. I
can't see how an onmousedown event could bubble up to an onload event.

NOTE: If you put an alert() statement in the onmousedown event handler the
body onload event doesn't get fired.

Example code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

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

<body onload="alert('loading page');">
<a href="./page.html" onmousedown="this.style.width = '25%';">test
mouse down</a>
</body>
</html>

Jul 20 '05 #1
2 6192
"Bender" <te*******@stickfly.com> writes:
I am wanting to capture an onmousedown event without firing the body tags
onload event.
It never calls the body onload event. The onload event is triggered by
the page being completely loaded. It only happens once, and doesn't
wait for you to click.
Also, if anyone could explain why this happens that would be excellent. I
can't see how an onmousedown event could bubble up to an onload event.
Let me guess: Your example code is saved as the file "page.html"?
In that case, clicking on the a-element will execute the onmousedown event,
and then follow the link and reload the page. That will ofcourse trigger
the onload event on the new page.

To stop the click from following the link, make the onmousedown event
handler return false. That is, add "return false" at the end of the
onmousedown attribute value.
NOTE: If you put an alert() statement in the onmousedown event handler the
body onload event doesn't get fired.
That shouldn't change anything, except maybe make you move the mouse.
Try using the keyboard to get rid of the alert (press return or
escape), and see if it makes a difference.
<a href="./page.html" onmousedown="this.style.width = '25%';">test
mouse down</a>


This test should fail. You try to set the width of an inline element,
which should have no effect at all. The CSS width propert doesn't
apply to inline elements. It will probably work in IE Quirks mode,
but your DOCTYPE should put the browser into standards mode.

Btw, your HTML is not legal. The a-element is an inline element, and
cannot be directly inside the body tag. It needs a paragraph, or
something similar, around it.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Lasse Reichstein Nielsen wrote:
"Bender" <te*******@stickfly.com> writes:
<a href="./page.html" onmousedown="this.style.width = '25%';">test
mouse down</a>
[...] The CSS width propert doesn't apply to inline elements.


JFTR: The `width' property does not apply to _non-replaced_
inline elements, table rows and row groups. Unfortunately,
the `a' element is in fact a non-replaced inline element.
Btw, your HTML is not legal.


Surely our robot won't be thrown in prison for that markup,
although one should think about it ;-) The markup is not _valid_.
PointedEars

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kicksave | last post by:
I've run across an interesting issue. On my development server (a Windows 2000 box), the onload event inside the <body> tag on .asp pages will not fire. Even if I take the time to build a...
5
by: Mike Hnatt | last post by:
I'd like the focus to be on "mycontrol" when the page is first loaded. I'm getting an undefined error and am assuming that I can't do this in the body ONLOAD event because the control is not yet...
2
by: Robbie | last post by:
Hi, I want to programatically fire an event. I have it working in IE, but Netscape won't work. What is the Netscape equivalent to, or a workaround for: document.myForm.myField.onchange(); ...
2
by: jva02 | last post by:
Hi, I'm confused why I can capture an event fired by an ActiveX object when it's loaded via an <object> tag, but not when loaded using "new ActiveXObject". Here's a basic example: vb ActiveX...
1
by: hal | last post by:
I have an application that includes an activex component that consumes resources that must be released when the a page is unloaded. Toward this end I subscribe to the unload event of the body...
1
by: Hal | last post by:
My most sincere gratitude to anyone who can help me work around this! I have work that needs to be done in javascript on the client whenever a page is unloaded. To this end, I subscribe to...
9
by: jon | last post by:
Hello, I'm trying to experiment with some javascript to do some custom dragdrop handling. I wish to use the onMouseDown event to trigger the start of my drag, and onMouseup for a potentential...
2
by: TH | last post by:
Hi there What's the best way for a popup to cause an event to fire in the opener? I've got a popup which currently returns a value to the opener by setting a hidden input in the opener: ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.