0

I'm trying to put that code to prevent right click on a img but i don't know what's wrong with that code. I think the script code is not where it should be.

<html>
<head>
    <meta charset='utf-8'/>
    <title></title>
    <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
</head> 
<body>
<img src="src image path">
<script>
    $(window).load(function() {
        $('img').bind('contextmenu', function(e) {
            return false;
        });
    };
</script>
</body>
</html>
2

2 Answers 2

1

You need to use the DOMReady function:

$(function() {  
    $('img').bind('contextmenu', function() {  
        return false;
    });
});

jsFiddle Demo

Sign up to request clarification or add additional context in comments.

Comments

0

Your document is not rendered at the time you are adding the bind event.

Try to do $(document).ready instead of $(window).load.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.