javascript - Protect jQuery function from outside access -
i'm using jquery in app registers user clicks perform given action through .click() binding, , want functionality available only through user mousedown. 1 of friends pointed out today it's possible run $(element).click() javascript terminal in firebug (or similar), , achieve same functionality clicking on element -- i'd prevent. ideas on how go doing this? input.
short answer: no, can't prevent it.
long answer: event click event
bound such called event handlers
. handlers functions
executed when given event occurs. if click on element, browser checks if event handlers
bound it, if fires
them. if not, browser try bubble up
event parent elements
, again checks if there event handlers
bound kind of event .. , forth.
jquerys
.trigger()
method (which call if calling .click()
instance) same thing. calls event handlers
bound specific element, specific event.
edit
there might simple ways somekind of soft detect
real click, instance might check toelement
property within event object
. property not set when triggered
. again, can fake aswell .trigger()
. example:
$(document).ready(function() { $('#invalid2').bind('click', function(e){ alert('click\nevent.target: ' + e.toelement.id); console.log(e); }); $('#invalid1').bind('click', function(){ $('#invalid2').trigger({ type: 'click', toelement: {id: 'fake'} }); }); });
working example: http://www.jsfiddle.net/v4wkv/1/
if call $('#invalid2').trigger('click')
toelement
property not there , therefore fail. can see, can add event object
.
Comments
Post a Comment