473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Cancel click event an a page

Hi all,

I have a page with many different elements: <a href="...."> ... </a>,
listboxes, radiobuttons, etc.

Can I use javascript to prevent the user from interacting with the
page? That is: can I intercept, alert the user, and cancel any click
event on the page?

Unfortunately, if the user clicks on a page element, the event bubbles
up from the element up in the hierarchy to the document, not
viceversa. I would like to intercept click events at document element
BEFORE they fires on the objects.

I know for example that onclick="return false" cancels events for <a>
elements, but still the user is able to interact with <select>
objects.

I have tried to place a large, transparent <DIV> with z-index=1000,
capture the onclick event and cancel it, but it doesn't work. Any
suggestion?

Regards,

Mauro
Jul 23 '05 #1
2 9739
On 19 Apr 2004 09:36:50 -0700, Paolo Mancini <pa******@yahoo.it> wrote:
I have a page with many different elements: <a href="...."> ... </a>,
listboxes, radiobuttons, etc.

Can I use javascript to prevent the user from interacting with the
page? That is: can I intercept, alert the user, and cancel any click
event on the page?
In some browsers, yes.
Unfortunately, if the user clicks on a page element, the event bubbles
up from the element up in the hierarchy to the document, not
viceversa. I would like to intercept click events at document element
BEFORE they fires on the objects.
Actually, events move from the document root to the event target, then
back up to the document root. This downward movement (propagation) is
called the event capture phase, the others being the "at target" and
"bubbling" phases, but IE knows nothing of this concept. I find this quite
surprising as even NN4 supports it in a rudimentary fashion.
I know for example that onclick="return false" cancels events for <a>
elements, but still the user is able to interact with <select>
objects.
Though the click event is always cancellable, browsers don't have to
honour it in every case. As Jim Ley pointed out to me recently, some
actions may be considered "application level", and so are outside the
scope of scripts. Displaying the drop-down list with a SELECT element will
undoubtably be one such case. Don't forget that some events can never be
cancelled, no matter what their target.
I have tried to place a large, transparent <DIV> with z-index=1000,
capture the onclick event and cancel it, but it doesn't work.
I wouldn't expect it to. Events should be directed to the deepest node
(not necessarily a leaf) in the document tree. Z-index shouldn't be a
factor in anything but presentation.
Any suggestion?


A general strategy would be laborious, and unreliable in some cases. If
built-in event capturing is unsupported, it would involve walking through
the entire document (therefore requiring a recent DOM-compliant browser)
and adding event listeners to all elements that you don't want to receive
events. You can stop propagation, so it won't be every element in the
document. Even then, some actions may still occur.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
On Mon, 19 Apr 2004 17:05:23 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:
A general strategy would be laborious, and unreliable in some cases. If
built-in event capturing is unsupported, it would involve walking through
the entire document (therefore requiring a recent DOM-compliant browser)
and adding event listeners to all elements that you don't want to receive
events. You can stop propagation, so it won't be every element in the
document. Even then, some actions may still occur.


IE's propriatary setCapture method can do this, and is a very useful
method, but nowhere near foolproof right click, left click, right
click almost always removes the capturing much to the amusement of
people asking me how to close a window after it all gone wrong.

there's not going to be a simple perfect solution, and if it's just to
suggest that a user not activate those links then it can be a useful
enhancement.

Jim.

--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MLH | last post by:
I tried the following code to prevent a checkbox from being updated (going from a value of Null to True, from True to False or from False to True). I was surprised it did not work. Can anyone...
0
by: Rachel Suddeth | last post by:
I have a tabbed ap, and I want to provide a message and give the user a chance to change there mind if they try to change tab pages in the middle of an update (otherwise just cancel the update and...
2
by: Stephen | last post by:
I have code which checks whether a datagrid is empty and if it is it shows a panel on my page. If its not empty then Im using the server.transfer to go to another page so as im able to use the...
5
by: Verde | last post by:
I'm using a 3rd party component in an ASP.NET 1.1 Web application. The component has a .Click event that can be fired from the client, with an associated event procedure in the code-behind module....
3
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set...
3
by: Gallarpri | last post by:
Hi, I'm making a dialog form with a textbox and 2 buttons: OK and Cancel. I want when I click on OK button, the program check the textbox, and if there is any error in the text introduced there,...
2
by: =?Utf-8?B?UmljaA==?= | last post by:
Is there a cancel argument for cancelling if you want to check or uncheck a checkbox? In the checkChanged event of a checkbox I ask the user if they are sure they want to check/uncheck...
7
by: John Gault | last post by:
I experimented with a snippet of JavaScript that will display a "Please Wait" message and graphic while the results of a cgi script is running (the script grabs a bunch of data and formats it in a...
13
Frinavale
by: Frinavale | last post by:
I've been trying all morning to cancel a form submit to the server. I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.