Connecting Tech Pros Worldwide Help | Site Map

question about captureEvents

  #1  
Old July 20th, 2005, 10:47 AM
Dave
Guest
 
Posts: n/a
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


  #2  
Old July 20th, 2005, 10:47 AM
Martin Honnen
Guest
 
Posts: n/a

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/

  #3  
Old July 20th, 2005, 10:48 AM
Dave
Guest
 
Posts: n/a

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]


  #4  
Old July 20th, 2005, 10:48 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a

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 - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
  #5  
Old July 20th, 2005, 10:48 AM
Dave
Guest
 
Posts: n/a

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>


  #6  
Old July 20th, 2005, 10:49 AM
Dave
Guest
 
Posts: n/a

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]


  #7  
Old July 20th, 2005, 10:49 AM
Dave
Guest
 
Posts: n/a

re: question about captureEvents


Thanks for your explanation


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capture Mouse Coordinates to variable mbatestblrock answers 4 January 9th, 2009 12:59 AM
Why does an invisible FORM tag have offSetLeft == 8?? Saqib Ali answers 11 July 20th, 2005 03:53 PM