Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
126
rated 0 times [  129] [ 3]  / answers: 1 / hits: 24179  / 10 Years ago, wed, january 21, 2015, 12:00:00

This is my sample code:



html



<div>
This is the Phone and NO ONE SHOULD RIGHT CLICK THIS! >:) </br>
<img class=tlClogo src=http://i.imgur.com/0atiS5C.jpg style=height: 120px; width:120px;>
</div></br></br></br></br>
And this is the Keyboard, ofcourse yo can right click this :)</br>
<img src=http://i.imgur.com/xkrKz1X.jpg style=height: 120px; width:120px;>


js



$('img').bind('contextmenu', function(e){
alert(This Logo is protected);return false;
});


fiddle



I want no one to be able to right click the 1st picture (cellphone) but other than that(keyboard) should be able to right click.



PS: I know this can be overriden by browsers but its okay :)


More From » jquery

 Answers
35

Came up with a solution.



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


Fiddle: http://jsfiddle.net/79k52rvu/4/



EDIT 1: Only the first one is now NOT right-clickable!



<html>
<body>
<div>
This is the Phone and NO ONE SHOULD RIGHT CLICK THIS! >:) </br>
<img class=tlClogo src=http://i.imgur.com/0atiS5C.jpg style=height: 120px; width:120px;>
</div>
</br></br></br></br>
And this is the Keyboard, ofcourse yo can right click this :)</br>
<img src=http://i.imgur.com/xkrKz1X.jpg style=height: 120px; width:120px;>

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js></script>
<script>
$('.tlClogo').bind('contextmenu', function(e) {
return false;
});
</script>
</body>
</html>


EDIT 2: Provided an HTML-doc


[#68143] Sunday, January 18, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
braydon questions
Tue, Nov 23, 21, 00:00, 3 Years ago
Mon, Dec 21, 20, 00:00, 4 Years ago
Fri, May 15, 20, 00:00, 4 Years ago
Fri, Mar 27, 20, 00:00, 4 Years ago
;