0

I have written the following JQuery which changes dynamically generated links on my Page (ruby on rails will_paginate) to GET requests which fetches JSON and refresh elements on my page. This works great in the case that they are left clicked. But in the event of a right click, the link GETS only JSON rendered information from my server and displays raw JSON in the a new window.

How can I revert back to the original link, in the event of Right Click?

// will_paginate + ajax 
// updates two divs: #pages and #pagelink
// see places#search controller; passes 4 parameters to the search action

$(function(){
  $(".pagination a").live("click", function(event) {
  event.preventDefault();

  // Javascript Regular expression function; extracts page number from full url
  var extractPageNumber = function(s) {
    var r=/page=(\d+)/, m=(""+s).match(r);
    return (m) ? Number(m[1]) : undefined;
  };
  var pageregex = extractPageNumber($(this).attr('href'));
  $(".pagination").html("Page is loading...")
  $.get("/event", {  event: $("input[name=event]").val(), page: pageregex }, function(data) {
    $('#pagelink').html(data.page_link);
    $('#tweets').html(data.html);
    });
  return false;
  });
});
JZ.
  • 21,147
  • 32
  • 115
  • 192
  • I see the evil `live` function. Switch to `delegate`:`$(".pagination").delegate('a',"click", function(event) { event.preventDefault(); . . .` – Levi Morrison Jun 23 '11 at 18:15

2 Answers2

1

See the answer to How to distinguish between left and right mouse click with jQuery on how to see a right click.

Community
  • 1
  • 1
Naftali
  • 144,921
  • 39
  • 244
  • 303
  • This doesn't seem to be working. Does it not play nice with live? – JZ. Jun 23 '11 at 18:24
  • I should note: This works once, only upon refresh. After I page through the links with left clicks THEN try the right click, it reverts back to JSON – JZ. Jun 23 '11 at 18:32
0

Check event.which == 1. This signifies left mouse button clicks.

Michael Mior
  • 28,107
  • 9
  • 89
  • 113