Friday 15 April 2011

javascript - Disable middle mouse button for modal dialog -


itemprop = "text">

I have such a problem: I have a link, which opens the Ajax dialog in the modal dialog at the top of the current page. But when I click on the middle button, it opens in a new tab, and everything is not in the modal window, but currently looks worse on the new tab page. So, my question is, how is it possible to disable the middle mouse button click for the current link?

  & lt; A class = "ajaxformDialog" ... & gt; & Lt; / A & gt; & Lt; Script & gt; $ (Function () {$ ('a.ajaxFormDialog') live ("click", function (e) {$ .ajax ({type: "POST", url: $ ("# formContent form"). ("Action"), data: $ ("# form content form"). Serialize (), success: function (data) {// ... do something}})}});  ;   

UPD I suggested you

  if (e.which == 2) {e.preventDefault (); }   

This probably stops defaults, but still opens a new tab with that form. When I click on the link with the middle / mouse wheel button, Does not even appear, that it is $ (function () ($ ($ ($ ('($ ($ ($' '' '' '), function (e) {...

UPD2 I wrote a code like this:

  $ (function () {$ ('a.ajaxFormDialog') live ("click", function (e) {console .log ("Which button is clicked:" + e.which); if (e.which = = 2) {e.preventDefault ();} // The remaining code ...   

So when I click the left mouse button, the console "which button is clicked on me: 1", but when I click on the middle / mouse wheel button As Yrfoks (and, possibly, Opera too), from the hands of developers have taken the middle-click behavior, I suggest changing the anchor node (s) with a different node I, like & lt; Span & gt; .

It sounds semantically correct, because & lt; A & gt; tag no longer acts as a real link in your usage scenario.

For such markup:

  & lt; A Class = "ajaxFormDialog" href = "#" & gt; Link's place & lt; / A & gt;   

You can use CSS like:

  a, .jaxFormDialog {color: orange; Text-decoration: underlined; Cursor: hand; } A: Hover, .jaxFormDialog: Hover {background: orange; White color; }   

and replace the anchor with span , including the ability to store any desired property and maintain any child's nodes (if any) .

  var genericHandler = function (e) {var al = $ (e. Goal); Var href = el.data ('href'); // Remove data console.log ('clicked span:', L, 'with stored href:', href); // work here}; $ ('A.ajaxFormDialog') Replace (with) (function () {var el = $ (this); console.log ('replacing element:', el); Return $ ("& lt; span & gt;") addClass ('AdX ($ ( This) .content ()) .data ('href', L.TRR '' href ''). // You can also click other data (GenericHandler);});   

It is less than all evils, if you want to avoid mid-click side effects for the moment.

No comments:

Post a Comment