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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to stop right click seems to need alert() in it

Status
Not open for further replies.

lwfg

Programmer
Feb 9, 2009
52
US
This script works to stop a right click from doing anything unless the alert() is taken out With it taken out, the right click does something.

1. Why is this ?
2. How do you make it work without the alert() ?

function f(e)
{
if (event.button==2)
{
alert('Please no right click.');
return false;
}
}
document.onmousedown=f

Thanks.
 
I don't think you can (I might very well be wrong), but I think you have to put some sort of a buffer in there...

On a side note - why on earth would you want to do this? I personally can't stand site that do it...


--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Thanks.
The reason is that I was asked to redirect pages in frames to pages with no information on them after a timeout of 20 minutes so users had to log in again. THe problem was that they could right click,back to see info that was supposed to be off the screen.
 
if the user disables javascript, they will still be able to right-click back.

They could also use the "back button" or "ALT <-" or the actual "back" key which is included on a lot of more recent keyboards.




--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
You can also just hit the Enter key while continuing to hold the right mouse button down. The alert window will disappear and the context menu will come up as usual. What makes this "trick" work is someone using the mouse for everything will click on the alert OK button which will cancel out the right click.

Lee
 
What are you using for your server side language? You could disable caching on the page which means the "back-button" becomes useless as the page would have to reload each time.




--------

GOOGLE is a great resource to find answers to questions like "how do i..."


--------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top