javascript - Intercept clicks, make some calls then resume what the click should have done before -


Good day all, I have to do this work:

Many, many are webpages, some Inside the element, there should be input, buttons, links, checkboxes etc. Some time should be javascript which can handle the element behavior, sometimes it is a simple & lt; A href = ".. .. .. .. & gt; link.

I have created a small javascript that will allow all clicks on clickable elements Prevents:

  $ (Document) .ready (function () {$ ('input [type = button], input [type = submit], input [type = checkbox], button , A '). Bind (' click ', function (evt), check) {if (typeof check ==' undefined ') {evt.preventDefault (); console.log ("id:" + evt.target.id + ", Category:" + evt.target.class + ", name:" + Evt.target.name); console.log (check); $ (evt.target). Trigger ('click', 'check' );}}});}); Logic: when some clubs are done, then I stop it, stop it, stop it Rack, call my track and then click trigger an event with an additional parameter, which does not trigger the track, then call again.  

But it's not working so well Submit clicks to do, but clicking on the checkbox, for example, it will be checked, but then it can not be unchecked, the link is only ignored, I track them (In console.log ()), but then the page remains there, nothing happens

Maybe I have guessed it incorrectly ... maybe I can Make a track call and then return true to some (//. .track call ... //). Done (returns true); or something ...

Anyone have any suggestions?

If you really want to wait with the click event, If you do not end up with, you can possibly do something like this here is an example for a link, but should be the same for other elements. In this example, click events fire after 2seconds, but in your case link.click () will be in the done () of the AJAX object.

  & lt; A href = "http://www.google.com" id = "myl" & gt; Google & lt; / A & gt; Var handled = {}; $ ("# Myl") ('Click', function (e) {var link = $ (this) [0]; if (! [Link ['id']] is controlled) {handled [link ['id']] = True; E.Pravant Default (); E.Stop Propagation (); // simulate async ajax call window .set timeout (function () {link.click ();}, 2000);} and {// handle the reset [Link ['id']] = false;}});  

Edit

So, for your example, something like this will appear

  var Handled = {}; $ (Document) .ready (function () {$ ('input [type = button], input [type = submit], input [type = checkbox], button, a'). Bind ('click', function (evt) }) {If (handled [evt.target.id]) {handled [evt.target.id] = true; evt.preventDefault (); evt.stopPropagation (); $ .ajax ({url: 'url' Data: {"id": evt.target.id, "class": evt.target.class, "name": evt.target.name}, done: function () {evt.target.click ();}} );} Other {handled [evt.target.id] = false;}}});  

Comments