Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to disable left mouse button click?

Status
Not open for further replies.

Draug

Programmer
Apr 18, 2001
77
CA
Hi,

Using IE5+, I am attempting to disable the left mouse button across the whole page.

I thought that having the code below would work. I know that the function is called when I left click and the onMouseDown event is raised. But, if I click on a button or element of the page that has an onClick event, the mouse press still occurs. Is there a way that I can intercept the onMouseDown event and cancell it, so that a complete click never occurs?

document.onMouseDown = myFunction();
myFunction ()
{
if (event.button == 1)
{
event.cancelBubble = true;
event.returnValue = false;
return false;
}
}


Thanks, I am grateful for any ideas!
Draug
 
Hi Draug,
Ok...here is "No Left Clicking"

<SCRIPT LANGUAGE=&quot;javascript&quot;>

function click() {
if (event.button==1) {
alert('No clicking!')
}
}
document.onMouseDown=click

</SCRIPT>

If you replace the '1' in the script with a 2, you'll have no RIGHT clicking ability. And if you change that line to read:

if (event.button==1 || event.button==2)

you'll have NO clicking at all!
Enjoy!
- Omicron -
 
hi
Draug, why don't you want to use onclick then? Victor
 
Omicron,
Is there anyway to do that without having the alert? So far, I have not found a way to do it.

Vituz,
I dont use the onClick because I only want to prevent the left click for a portion of time. To be specific, I want to stop clicks while my application does some lengthy executions of servlets (I also change the cursor to busy at that time across the whole page). I am attempting to mimic the user interaction that would occur with a desktop application. I have some ideas to try with the onClick, and will try those today.

Thanks for taking the time to respond guys. Hopefully someone has some more ideas.

Draug
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top