views:

30

answers:

1

Is it possible to have a link, once clicked, execute the href target, but not pop up a new window?

+3  A: 

I presume you mean using jQuery, since you have tagged it as such. Using an ajax call will hit the page and, if you wish, you could perform actions on finish. e.preventDefault will stop the click (visiting the url) to occuring.

Something like this?

$("a#mylink").click(function(e){
   var goto = $(this).attr('href'); //get the url
   $.ajax({
      url: goto
   }); //execute the href
   e.preventDefault(); //prevent click
});

Ajax jQuery reference

neatlysliced
Do I just set the Id of the link to myLink?
George
You could do that, or something semantic to your page. If it already has a class or ID on there you could use that and change the jQuery.
neatlysliced