Friday, 15 July 2011

javascript - Detect if button click real user or triggered by a script -



javascript - Detect if button click real user or triggered by a script -

is there method enables me observe whether button click performed real user , not automated method (javascript) user has loaded onto browser developer console or other browser developer tool?

i tried next methods suggested in various stackoverflow posts none of them appear work. ref: how observe if click() mouse click or triggered code?

script detection methods tried , failed:

mybutton.click(function (e) { if (!e.which) { //triggered code not clicked alert(' e.which - not real button click') } else if ('istrusted' in e && !e.istrsuted) { //triggered code not clicked alert(' e.istrusted - not real button click') } else if (e.originalevent === undefined) { //triggered code not clicked alert(' e.originalevent - not realbutton click') } // else if (!e.focus) { // //triggered // not observe e.focus on real btn click // alert(' e.focus - not realbutton click') // } else { // button clicked real user , not script } })

if run next script trigger button click chrome browser console none of methods above traps beingness triggered script.

var button = document.getelementbyid("btnsubmit"); button.click();

==========================================================================

thank responses , stackoverflow providing such great site facilitates much knowledge sharing , saving techies untold number of hours.

it appears still not have reliable method. 3 browsers (ff, ie & chrome) provide developer/console interfaces user run/inject javascript on webpage. appears each browser flavor traps event property values little differently. example: chrome traps difference between script activated cick , real user e.screenx in ie: e.screenx has same value both script click (synthetic) , user button click

the next detection methods either did not work @ or inconsistent across different browsers: e.which e.istrsuted e.originalevent (event.source != window) (e.distance != null)

the mousedown event appears triggered real user button click, have assume there script method emulate mousedown in add-on button click event

$(me.container + ' .mybutton').mousedown(function (e) { alert('mouseisdown real button click'); }

if can figure out reliable method works across multiple browsers, detects difference between synthetic (script) button click , button click user, deserve superhero status.

when button click happens through mouse, event e has mouse pointer location recorded. seek :

if(e.screenx && e.screenx != 0 && e.screeny && e.screeny != 0){ alert("real button click"); }

javascript browser

No comments:

Post a Comment