1. I've started a massive SPAM purge, any accounts that have spammed are being removed, also for a short period new user signups are disallowed until the SPAM cleaning is finished.

disable right click on images?

Discussion in '(X)HTML / CSS' started by aadhar, Aug 28, 2009.

  1. aadhar

    aadhar New Member

    Joined:
    Aug 28, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Is there any simple or easy way to disable right click on images?

    I searched on Google but found some very long codes to insert to disable the right click

    Thanks for your help.
    Loading...
  2. ABudgetWebHost

    ABudgetWebHost New Member

    Joined:
    Aug 22, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    While I do see the need for this, I would advise against it due to the fact that Google seems to hate javascript! Instead, if you have CPanel, you can go and setup hotilink protection. This will stop people from being able to use your images on other pages and stealing your bandwidth. But, if you're worried that they will just steak the image all together, you can use the following javascript code:

    Code (Text):
    <script language="JavaScript1.2">

    var clickmessage="Right click disabled on images!"

    function disableclick(e) {
    if (document.all) {
    if (event.button==2||event.button==3) {
    if (event.srcElement.tagName=="IMG"){
    alert(clickmessage);
    return false;
    }
    }
    }
    else if (document.layers) {
    if (e.which == 3) {
    alert(clickmessage);
    return false;
    }
    }
    else if (document.getElementById){
    if (e.which==3&&e.target.tagName=="IMG"){
    alert(clickmessage)
    return false
    }
    }
    }

    function associateimages(){
    for(i=0;i<document.images.length;i++)
    document.images[i].onmousedown=disableclick;
    }

    if (document.all)
    document.onmousedown=disableclick
    else if (document.getElementById)
    document.onmouseup=disableclick
    else if (document.layers)
    associateimages()
    </script>
    Add this code to the END of your page, right above the </body> tag.

    Hoep this helps!
  3. cyberdesignz

    cyberdesignz Member

    Joined:
    Jun 17, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    thanks ABudgetWebHost you have solved my problem too. thanks for such informative post.
  4. cyberdesignz

    cyberdesignz Member

    Joined:
    Jun 17, 2010
    Messages:
    83
    Likes Received:
    0
    Trophy Points:
    6
    Thanks dude! for giving such nice reply i was in search of same scenario.
  5. HotterDV

    HotterDV Member

    Joined:
    Jan 13, 2010
    Messages:
    52
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    New Delhi, India
    I tried the above given code but it did not work. I past the code as it is before ending body tag.
  6. proweb

    proweb Well-Known Member

    Joined:
    Jul 21, 2009
    Messages:
    1,292
    Likes Received:
    48
    Trophy Points:
    48
    Location:
    Joomla Expert
    Here is a javascript code which I use to disable right click on pages. This is for the whole page and not only for images; it may be useful to you or for someone else.

    Code (Text):

    <script>
    function right(e) {
        if ((document.layers || (document.getElementById && !document.all)) && (e.which == 2 || e.which == 3)) {
          alert("© Copyright Yourwebsite");
          return false;
        }
        else if (event.button == 2 || event.button == 3) {
          alert("© Copyright Yourwebsite");
          return false;
        }
        return true;
      }
      if (document.layers){
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = right;
      }
      else if (document.all && !document.getElementById){
        document.onmousedown = right;
      }
        document.oncontextmenu = new Function("alert('© Copyright Yourwebsite');return false");
    </script>
     

Share This Page