472,143 Members | 1,340 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

question about captureEvents

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
Jul 20 '05 #1
6 13724


Dave wrote:
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


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/

Jul 20 '05 #2
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" <Ma***********@t-online.de> schreef in bericht
news:3F**************@t-online.de...


Dave wrote:
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


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/

Jul 20 '05 #3
"Dave" <no@dsfg.vb> writes:
But i still can click on the menu and other buttons of the browser. Is it
not possible to make this impossible?


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
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>
Jul 20 '05 #5
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" <do*************@senet.andthis.com.au> wrote in message
news:Y7*****************@nnrp1.ozemail.com.au...
Dave wrote:
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

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

Jul 20 '05 #6
Thanks for your explanation
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stevey | last post: by
6 posts views Thread by Vincent van Beveren | last post: by
8 posts views Thread by Brian Wilson | last post: by
5 posts views Thread by Rocky Moore | last post: by
10 posts views Thread by glenn | last post: by
reply views Thread by leo001 | last post: by

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.