473,379 Members | 1,302 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,379 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 6190
"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: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.