I have this code below for no right click but it only works in IE how do i make it also work in Firefox.
You can try with this code: <script type="text/javascript"> function md(e) { try { if (event.button==2||event.button==3) return false; } catch (e) { if (e.which == 3) return false; } } document.oncontextmenu = function() { return false; } document.ondragstart = function() { return false; } document.onmousedown = md; </script> Code (markup): I don't like alert boxes, but you can on md function.
The following code will display the alertbox. But it will still show the context menu. The only way to disable context menu is to use ajsa52's code. But even that cannot be guaranteed to work. Becoz in Firefox, user can decide whether to allow or disallow JavaScript to replace or disable context menu. <script language="JavaScript"> var message="Sorry Right Click is Disabled!"; // Message for the alert box // Don't edit below! function click(e) { if(document.all) { if (event.button == 2) { alert(message); return false; } }else if(document.layers || document.getElementById){ if (e.which==2||e.which==3){ alert(message); return false; } } } if (document.layers) { document.captureEvents(Event.MOUSEDOWN); } document.onmousedown=click; // --> </script> Code (markup): I am against any code that interfere with the normal usage of the user. Becoz, if a person wants to see your page source or save your image, he can do it irrespective of what ever you do. There is no script that can disable that. The best option is to write a copyright notice in your page. If that doesn't stop your user, nothing will.
The only thing that type of script ever achieves is to interfere with browser operation. You and your site will appear be less un-professional without it.
Hi i agree with you, in my opinion if we don't use alert box it will make our visitor don't know if we have disabled right click
Some times we need to disable the right click option in the web browser for security reason .The following code can be used to implement this in the best way. <script language ="javascript" > function DisableRightClick() { if (event.button == 2) { alert("Right Click is not possible Here !") } } document.onmousedown=DisableRightClick; </script >
What reason? What do you think it will prevent? That code is I.E. - only, which the O.P. didn't want. Here is my definitive 'no right click' script (which I don't use): <script type = "text/javascript"> function disableRightClick( e ) { var evt = e || window.event; if( (evt.button && evt.button == 2) || ( evt.which && evt.which & 2) ) { alert("An attempt has been made to disable right-clicking on this page.\n\nMost browsers can be configured to stop scripts dong this so it makes you wonder why we bothered, especially as all functionality that right-clicking provides is available by other means.\n\nPlease contact us to advise us not to do this, as it just makes us look stupid."); } } document.onmousedown = disableRightClick; </script> Code (markup):
this code will disable right click for all browsers function md(e) { try { if (event.button==2||event.button==3) return false; } catch (e) { if (e.which == 3) return false; } } document.oncontextmenu = function() { return false; } document.ondragstart = function() { return false; } document.onmousedown = md; Refer this link http://thedotnetdeveloper.blogspot.in/2011/12/disable-right-click-in-all-browsers.html