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!

Needs help - how to disable right mouse button

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,

I need to disable right mouse button in my application. The main reason for this is I don't what to diplay context menu on right mouse click. I could able to disable the mouse button in IE browser. But I could not able to do the same in Netscape version 4+. Here is my code

window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){
if(e.target==document)return false;
}

This code works fine when you click right mouse button on the document, but if i click right mouse button on links, or other elements on the browser, I could not able to disable the context menu. I appreciate if any one gives a tip.

Thanks,
Gorijavolu.
 
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- start hide

document.onmousedown = click;

if (document.layers)
document.captureEvents(Event.MOUSEDOWN);

function click(e)
{
if (document.all)
if (event.button == 2)
{
document.write(&quot;&quot;); // need to do this to &quot;fool&quot; IE
return false;
}
if (document.layers)
if (e.which == 3)
{
return false;
}
}

// end hide -->
</SCRIPT> [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Hi,

I tried using the script above in my web page to disable the ability to right click and every time I test it and try to right click my browser freezes. Any ideas as to why this is happening?

Thanks. s-)
 
Whenever I visit a site that uses this script I automaticaly leave. It's a waste of time and memory.
 
Well, if this script is a waste of time and memory, do you have any other suggestions? My problem is that I have a file for users to download and if they right click and save target as... instead of following the link and doing a save as... the file saves as a .doc extension, which it should not be.

 
For IE you can add
Code:
oncontextmenu=&quot;return false&quot;
to the <body> tag...
 
hi!
just found this script, may be of use:
<script language=&quot;JavaScript1.2&quot;>
if(window.Event)
document.captureEvents(Event.MOUSEUP);function nocontextmenu()
{event.cancelBubble=true
event.returnValue=false;return false;}function norightclick(e)
{if(window.Event)
{if(e.which==2||e.which==3)
return false;}else
if(event.button==2||event.button==3)
{event.cancelBubble=true
event.returnValue=false;return false;}}document.oncontextmenu=nocontextmenu;document.onmousedown=norightclick;
</script>


regards, vic
 
The addition in the body tag worked great! (at least for IE) Thanks!
:p
 
<script language=&quot;JavaScript&quot;>
// NO RIGHT CLICKS
browser_name = navigator.appName;
browser_version = parseFloat (navigator.appVersion);
bname = &quot;Brold&quot;;
if (browser_name == &quot;Netscape&quot;) { bname = &quot;NS&quot;; };
if (browser_name == &quot;Microsoft Internet Explorer&quot;) { bname = &quot;IE&quot;; };
msg = &quot;Sorry, right-clicking is currently unavailable.&quot;;
function RClick (evnt)
{
if (bname == &quot;IE&quot;)
if (event.button == 2)
{
alert (msg);
return false;
}
if (bname == &quot;NS&quot;)
if (evnt.which == 3)
{
alert(msg);
return false;
}
}
if (bname == &quot;NS&quot;)
document.captureEvents (Event.MOUSEDOWN);
document.onmousedown = RClick;
//-->
</script>
 
Does somebody know how i can make slideshows without having to make several pages?
 
Hey, this no right click script should work fine!
- Put this in the <body> tag

------

<style>*{filter:flipv ! important}</style>
<script language=&quot;JavaScript1.2&quot;>
if(window.Event)
document.captureEvents(Event.MOUSEUP);function nocontextmenu()
{event.cancelBubble=true
event.returnValue=false;return false;}function norightclick(e)
{if(window.Event)
{if(e.which==2||e.which==3)
return false;}else
if(event.button==2||event.button==3)
{event.cancelBubble=true
event.returnValue=false;return false;}}document.oncontextmenu=nocontextmenu;document.onmousedown=norightclick;
</script>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top