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;
});
});