Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

question about captureEvents

Question posted by: Dave (Guest) on July 20th, 2005 09:47 AM
Hi,

With this code, I thought that any 'click' with the mouse would be captured
on the window level and nothing would happen, but a click on the button
triggers nevertheless the function hit(). Why is it not directed to the
function IgnoreEvents instead of the function hit?
....
<script>
window.top.captureEvents(Event.CLICK)
window.top.onclick=IgnoreEvents

function IgnoreEvents(e)
{ return false }

function hit()
{ alert('hit') }
</script>

INPUT TYPE="button" onClick="hit()"
....

Thanks for your explanation
Dave


Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
July 20th, 2005
09:47 AM
#2

Re: question about captureEvents


Dave wrote:[color=blue]
> Hi,
>
> With this code, I thought that any 'click' with the mouse would be captured
> on the window level and nothing would happen, but a click on the button
> triggers nevertheless the function hit(). Why is it not directed to the
> function IgnoreEvents instead of the function hit?
> ...
> <script>
> window.top.captureEvents(Event.CLICK)
> window.top.onclick=IgnoreEvents
>
> function IgnoreEvents(e)
> { return false }
>
> function hit()
> { alert('hit') }
> </script>
>
> INPUT TYPE="button" onClick="hit()"
> ...
>
> Thanks for your explanation[/color]

captureEvents is part of the NN4 event model, and with NN4 I am sure you
can click the button as much as you want, it doesn't fire its onclick
handler:

<html>
<head>
<title>NN4 captureEvents</title>
<script type="text/javascript">
if (document.layers) {
window.captureEvents(Event.CLICK);
window.onclick = function (evt) {
return false;
}
}
</script>
</head>
<body>
<form>
<input type="button" value="button"
onclick="alert(event.type);">
</form>
</body>
</html>

I guess you are trying with Netscape 6/7 or Mozilla which unfortunately
has window.captureEvents as a function in its browser object model but
this doesn't do anything.
If you want to capture events with Netscape 6/7 or Mozilla use
window.addEventListener('eventname', eventHandler, true)
as in

<html>
<head>
<title>NN4 captureEvents</title>
<script type="text/javascript">
if (document.layers) {
window.captureEvents(Event.CLICK);
window.onclick = function (evt) {
return false;
}
}
else if (window.addEventListener) {
window.addEventListener('click',
function (evt) {
if (evt.stopPropagation) {
evt.stopPropagation();
return false;
}
},
true
);
}
</script>
</head>
<body>
<form>
<input type="button" value="button"
onclick="alert(event.type);">
</form>
</body>
</html>

--

Martin Honnen
http://JavaScript.FAQTs.com/


Dave's Avatar
Dave
Guest
n/a Posts
July 20th, 2005
09:48 AM
#3

Re: question about captureEvents
Thanks again, it works with NN 7.
But i still can click on the menu and other buttons of the browser. Is it
not possible to make this impossible?

Dave


"Martin Honnen" <Martin.Honnen@t-online.de> schreef in bericht
news:3F44F697.9050905@t-online.de...[color=blue]
>
>
> Dave wrote:[color=green]
> > Hi,
> >
> > With this code, I thought that any 'click' with the mouse would be[/color][/color]
captured[color=blue][color=green]
> > on the window level and nothing would happen, but a click on the button
> > triggers nevertheless the function hit(). Why is it not directed to the
> > function IgnoreEvents instead of the function hit?
> > ...
> > <script>
> > window.top.captureEvents(Event.CLICK)
> > window.top.onclick=IgnoreEvents
> >
> > function IgnoreEvents(e)
> > { return false }
> >
> > function hit()
> > { alert('hit') }
> > </script>
> >
> > INPUT TYPE="button" onClick="hit()"
> > ...
> >
> > Thanks for your explanation[/color]
>
> captureEvents is part of the NN4 event model, and with NN4 I am sure you
> can click the button as much as you want, it doesn't fire its onclick
> handler:
>
> <html>
> <head>
> <title>NN4 captureEvents</title>
> <script type="text/javascript">
> if (document.layers) {
> window.captureEvents(Event.CLICK);
> window.onclick = function (evt) {
> return false;
> }
> }
> </script>
> </head>
> <body>
> <form>
> <input type="button" value="button"
> onclick="alert(event.type);">
> </form>
> </body>
> </html>
>
> I guess you are trying with Netscape 6/7 or Mozilla which unfortunately
> has window.captureEvents as a function in its browser object model but
> this doesn't do anything.
> If you want to capture events with Netscape 6/7 or Mozilla use
> window.addEventListener('eventname', eventHandler, true)
> as in
>
> <html>
> <head>
> <title>NN4 captureEvents</title>
> <script type="text/javascript">
> if (document.layers) {
> window.captureEvents(Event.CLICK);
> window.onclick = function (evt) {
> return false;
> }
> }
> else if (window.addEventListener) {
> window.addEventListener('click',
> function (evt) {
> if (evt.stopPropagation) {
> evt.stopPropagation();
> return false;
> }
> },
> true
> );
> }
> </script>
> </head>
> <body>
> <form>
> <input type="button" value="button"
> onclick="alert(event.type);">
> </form>
> </body>
> </html>
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>[/color]



Lasse Reichstein Nielsen's Avatar
Lasse Reichstein Nielsen
Guest
n/a Posts
July 20th, 2005
09:48 AM
#4

Re: question about captureEvents
"Dave" <no@dsfg.vb> writes:
[color=blue]
> But i still can click on the menu and other buttons of the browser. Is it
> not possible to make this impossible?[/color]

Generally, no. I wouldn't want to use a browser where it is possible,
and most users would find it highly annoying anyway.
The safest is to just forget the idea.

Please don't top post.
/L
--
Lasse Reichstein Nielsen - Join Bytes!
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Dave's Avatar
Dave
Guest
n/a Posts
July 20th, 2005
09:48 AM
#5

Re: question about captureEvents
Look at those very similar scripts: with the first, using a window, every
click of the mouse (even menus and buttons) is blocked as long as the
created window is open. With the second script, using a button, it should be
the same as long as the value of the button is not 'changed', but it doesn't
work. I can click anywhere.
If you could tell me why, it would be great (both scripts running with NN
7). Thanks in advance.
Dave

script 1:

<INPUT TYPE="button" value="block everything" onclick="start()">
<INPUT TYPE="button" VALUE="anything" onclick="myfunction()">
<SCRIPT>
var winModalWindow

function start()
{
window.top.captureEvents(Event.CLICK|Event.FOCUS)
window.top.onclick="return false"
window.top.onfocus=HandleFocus
xx="left=500,top=300,dependent=yes"
winModalWindow = window.open("win2.htm","",xx)
winModalWindow.focus()
}


function HandleFocus()
{
if (winModalWindow)
{
if (!winModalWindow.closed)
{
winModalWindow.focus()
}
else
{
window.top.releaseEvents (Event.CLICK|Event.FOCUS)
window.top.onclick = ""
}
}
return false
}

function myfunction()
{
alert("ok")
}
</script>



script 2:

<INPUT id="bu" TYPE="button" VALUE="should block" onclick="start()">
<INPUT TYPE="button" VALUE="anything" onclick="myfunction()">
<INPUT TYPE="button" VALUE="changed" onclick="change()">

<SCRIPT>
var winModalWindow

function start()
{
window.top.captureEvents(Event.CLICK|Event.FOCUS)
window.top.onclick="return false"
window.top.onfocus=HandleFocus
winModalWindow = document.getElementById("bu")
winModalWindow.focus()
}

function HandleFocus()
{
if (winModalWindow)
{
if (! (winModalWindow.value=="changed"))
winModalWindow.focus()
else
{
window.top.releaseEvents (Event.CLICK|Event.FOCUS)
window.top.onclick = ""
}
}
return false
}


function myfunction()
{
alert("ok")
}

function change()
{
document.getElementById("bu").value="changed"
}
</script>



Dave's Avatar
Dave
Guest
n/a Posts
July 20th, 2005
09:49 AM
#6

Re: question about captureEvents
Look at my post just above yours and you will see that in the first script,
it's impossible to click at anything, included buttons and menus (with NN7).
My question was: why does the second script not work?

Dave


"Dom Leonard" <doml.removethis@senet.andthis.com.au> wrote in message
news:Y7r1b.438$Ca5.12064@nnrp1.ozemail.com.au...[color=blue]
> Dave wrote:
>[color=green]
> > Thanks again, it works with NN 7.
> > But i still can click on the menu and other buttons of the browser. Is[/color][/color]
it[color=blue][color=green]
> > not possible to make this impossible?
> >
> > Dave
> >
> >[/color]
> A thought is that capturing click events will not itself disable menus
> and buttons driven by mousedown/mouseup instead of click events. If the
> case, these would need separate listeneres/event capture.
>
> A quick google suggests that Internet Explorer 6 does not support event
> capture as per DOM2 recommendations - meaning it does not support
> addEventListener registration - but does have its own attachEvent and
> detachEvent methods. As far as I can determine IE does not support event
> capture at all and would need modifications to event handlers at the
> HTML tag or DOM node object level to get around the limitation.
>
> Cheers,
> Dom
>[/color]



Dave's Avatar
Dave
Guest
n/a Posts
July 20th, 2005
09:49 AM
#7

Re: question about captureEvents
Thanks for your explanation



 
Not the answer you were looking for? Post your question . . .
182,534 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors