Question

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>
Was it helpful?

Solution

You need to use the DOMReady function:

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

jsFiddle Demo

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top