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

Disable right-click 1

Status
Not open for further replies.

annie79

Programmer
Sep 30, 2003
5
0
0
US
How to disable the context-menu of the browser?

I already have a JS function for that but it is still not possible to prevent the right-click if the alert is removed by keypress while holding the mouse right-button.

My function is as below:

<SCRIPT>
function fnRightClickDisable() {
if(event.button == 2 || event.button == 3) {
alert(&quot;Right-click is disabled&quot;);
return;
}
}
</SCRIPT>
<SCRIPT LANGUAGE = &quot;JavaScript&quot;>document.onmousedown = fnRightClickDisable</SCRIPT>
 
What is it that you are actually wanting to do? Perhaps there is a better way?

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
This is what I am trying to do...
1. The function is added to disable right-click. So on right-clicking the page an alert is displayed, which should have prevented the context-menu.
2. If we keep holding the right mouse-button even after the menu is popped and press SpaceBar from keyboard, the alert will vanish.
3. Then, on releasing the right mouse-button, the menu still appears.

Is there a way to solve this problem???
 
Yeah, use better code :)
Code:
document.oncontextmenu = new Function(&quot;return false&quot;);
 
That will work if the user happens to have JavaScript switched on.

I'd be interested as to why you would need to disable the context menu.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
me also :)

Yet to hear a good use for it

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
addendum:
.. or see a big, popular, profitable site do it.

I wonder if there's a correlation.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
The other thing is, on my lovely ergonomic M$-knockoff keyboard I have a key for context menu. So fudging the onmousedown event has absolutely no bearing on whether or not the context menu displays.

[sub]Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top