www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Validate code

  1. #1
    Join Date
    Feb 2010
    Location
    Berlin
    Posts
    97

    resolved [RESOLVED] Validate code

    I am using this line of code to prevent right-click (and subsequently save image):
    Code:
    <img src="img/myimage.jpg" onMouseDown="if (event.preventDefault) event.preventDefault()" oncontextmenu="return false;" >
    It's a standard code, except that the browser warning is suppressed. And it works fine.
    Unfortunately, this is not valid coding. So, is there a way to fix it?

    Oh, and please no discussions about preventing theft from websites. I know nothing really works, I just want to deter the majority of web users.

    Thanks in advance.
    Last edited by Pris; 08-08-2011 at 02:11 PM. Reason: correction of a very dumb typo

  2. #2
    Join Date
    May 2011
    Posts
    194

    maybe this

    Hi,

    check event object an method .preventDefault()
    for Microsoft Interne Explorer see http://msdn.microsoft.com/en-us/library/ms535863.aspx

    if(event.preventDefault)

    this check a pointer like if(event.preventDefault!=null)

  3. #3
    Join Date
    Feb 2010
    Location
    Berlin
    Posts
    97
    Thanks twseitex, will look into your solution asap.

  4. #4
    Join Date
    Feb 2010
    Location
    Berlin
    Posts
    97
    Found a jQuery snippet that works nicely:
    Code:
    <script type="text/javascript">
    $('img').ready(function(){
    $('img').bind("contextmenu",function(e){
    return false;
    });
    });
    </script>
    Note: it comes from here and I adapted it. The original code disables right-click completely, but I do want visitors to be able to open links in new tabs or copy text. So here you go, disable right-click on images with jQuery.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles