1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Disable Right Click in IE and Firefox

Discussion in 'JavaScript' started by netpox, Feb 27, 2007.

  1. #1
    I have this code below for no right click but it only works in IE how do i make it also work in Firefox.

     
    netpox, Feb 27, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    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.
     
    ajsa52, Feb 27, 2007 IP
  3. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #3
    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.
     
    Aragorn, Feb 28, 2007 IP
  4. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #4
    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.
     
    Logic Ali, Feb 28, 2007 IP
  5. leakngakak

    leakngakak Greenhorn

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    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 :D
     
    leakngakak, Feb 22, 2009 IP
  6. franklinrony

    franklinrony Guest

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks for the code, its only work with imgs?
     
    franklinrony, Jul 5, 2009 IP
  7. elizas

    elizas Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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 >
     
    elizas, Apr 19, 2010 IP
  8. Logic Ali

    Logic Ali Well-Known Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    108
    #8
    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):
     
    Logic Ali, Apr 19, 2010 IP
  9. Transporter

    Transporter Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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​
     
    Transporter, Mar 15, 2012 IP