Catching window events

V

vijay21

hi all,

This is about javascript window events. I have a simple html file like
this
<html>
<head>
</head>
<body onmousedown="alert()">
<form>
<input type="text">
</form>
</body>
</html>

But alert is only popped whenever I click the mouse near by the input
field. It is not catching the event for the entire browser window. Can
anyone point out what is wrong in this html?

Thanks,
Vijay
 
J

Joakim Braun

hi all,

This is about javascript window events. I have a simple html file like
this
<html>
<head>
</head>
<body onmousedown="alert()">
<form>
<input type="text">
</form>
</body>
</html>

But alert is only popped whenever I click the mouse near by the input
field. It is not catching the event for the entire browser window. Can
anyone point out what is wrong in this html?

The answer is probably that the body by default doesn't extend to fill the
entire browser window.

Try adding some CSS that makes height/width of body 100%.
 
V

vijay21

Hi Joakim,

I tried adding body style="height:100%;width:100%" to the body tag.
Now, it is always displaying scroll bars inside the explorer. It is
also not truly encompassing the whole browser window. It's 0,0
coordinates seem to be startting from the point text box appears. The
thin margins on the top left are not capturing the event.

Is there some way by which I can add the eventhandler to the window
itself and not just body? I think I have seen such pages where they do
such stuff.

Thankyou for helping...
 
B

Bonnett

Hi Joakim,

I tried adding body style="height:100%;width:100%" to the body tag.
Now, it is always displaying scroll bars inside the explorer. It is
also not truly encompassing the whole browser window. It's 0,0
coordinates seem to be startting from the point text box appears. The
thin margins on the top left are not capturing the event.

Is there some way by which I can add the eventhandler to the window
itself and not just body? I think I have seen such pages where they do
such stuff.

Thankyou for helping...

Try:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en-GB">
<head>
<title>Window Alert</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<script type="text/javascript">
window.onmousedown = function() { alert("This will get really
irritating."); };
</script>
</head>
<body>

</body>
</html>
 
F

Fred Oz

hi all,

This is about javascript window events. I have a simple html file like
this
<html>
<head>
</head>
<body onmousedown="alert()">
<form>
<input type="text">
</form>
</body>
</html>

But alert is only popped whenever I click the mouse near by the input
field. It is not catching the event for the entire browser window. Can
anyone point out what is wrong in this html?

Thanks,
Vijay

<style type="text/css">
body {border: 0; margin: 0; width: 100%; height: 100%;}
</style>

If IE persists with scrollbars, reduce width/height to 99%. IE 5.2
on Mac doesn't show scrollbars at 100%.
 
V

vijay21

Hi Bonnett,

This is running really well on Mozilla but I don't know why it is not
doing anything on Internet Explorer. Looks like IE is completely
ignoring this. Any guesses why so...

Thankyou very much,
 
B

Bonnett

After a quick google + test, it seems IE uses document.mousedown rather
than window.mousedown, however I do not know what the browser
limitations are on this, mozilla firefox 1.0.3 accepts
document.mousedown, but older version may not.
 
V

vijay21

Hi Bonnet and Fred,
Many thanks for fishing this out. I have got what I wanted.
Thanks,
 
R

RobB

hi all,

This is about javascript window events. I have a simple html file like
this
<html>
<head>
</head>
<body onmousedown="alert()">
<form>
<input type="text">
</form>
</body>
</html>

But alert is only popped whenever I click the mouse near by the input
field. It is not catching the event for the entire browser window. Can
anyone point out what is wrong in this html?

Thanks,
Vijay

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/str­ict.dtd">
<html>
<head>
<style type="text/css">
html { padding: 20px; cursor: help; }
body { margin:0; height:100%; }
input { cursor: help; }
</style>
<script type="text/javascript">
document.getElementsByTagName('html')[0].onmousedown =
function(e)
{
e = e || window.event;
tgt = e.srcElement || e.target;
alert(tgt.tagName);
}
</script>
</head>
<body>
<form>
<input type="text">
</form>
</body>
</html>

http://www.meyerweb.com/eric/css/discuss/examples/all-shown.html
http://www.molly.com/2005/02/18/root-element-html/

btw moz/gecko requires arguments to alert(...)
 
T

Thomas 'PointedEars' Lahn

I tried adding body style="height:100%;width:100%" to the body tag.
Now, it is always displaying scroll bars inside the explorer.

1. [X] You only know Internet Explorer. [psf 2.9]

<OT>

2. You have to format the element position:absolute, too. Tests (with
ObjectInspector) showed that the following stylesheet is suited for
the task:

body {
position:absolute;
margin:0;
width:99%;
height:99%;
}

html>body {
width:auto;
height:auto;
left:0;
top:0;
right:0;
bottom:4px;
}

</OT>


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
473,787
Messages
2,569,629
Members
45,330
Latest member
AlvaStingl

Latest Threads

Top