question about captureEvents

D

Dave

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
 
M

Martin Honnen

Dave said:
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>
 
D

Dave

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
 
L

Lasse Reichstein Nielsen

Dave said:
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
 
D

Dave

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>
 
D

Dave

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
 

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

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top