javascript - How to re-enable RightClick only for specific tag/id -


i'm using code:

document.oncontextmenu = (function() {    var counter = 0;    return function() {         counter++;        if (counter == 3) {            $("<div id='r-click'></div>").appendto("#container").html("<span>!!! protected content !!!</span>").fadein(500).show().delay(4000).fadeout(800, function() {            counter = 0;        });        }        return false;    }; })(); 

now, issue have textarea html code banner, , need context menu appear on it. possible edit code i'm using?

you need use event object, passed oncontextmenu function.

here solution:

document.oncontextmenu = function(e) {     var self = this;     self.cnt = self.cnt || new(function() {         this.counter = 0;     });      if (e.target.id !== "somebannerid") {         return false;     } else {         self.cnt.counter++;         if (self.cnt.counter === 3) {             $('#r-click').remove();             $("<div id='r-click'></div>").appendto("#container").html("<span>!!! protected content !!!</span>").fadein(500).show().delay(3000).fadeout(800, function() {                 self.cnt.counter = 0;             });         }     } }; 

update: working example https://jsfiddle.net/3k9kl0xr/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -