Reputation: 4908
I want to have a link that does NOT redirect the main window, but opens a new window (popup, if you dare!).
Here is my code:
<%= link_to "Print Label", {:action => "show_label"}, :method => :get, 'data-popup' => true %>
With javascript:
<script type="text/javascript" charset="utf-8">
$('a[data-popup]').live('click', function(e) {
window.open($(this)[0].href);
e.preventDefault();
});
</script>
What happens is that a new window opens but ALSO the main window moves on the link as well. It is like preventDefault is not stopping the action.
Any ideas?
Upvotes: 0
Views: 1089
Reputation: 1283
I used
$(function () {
$("a[data-popup]").bind('click', function(e) {
window.open($(this)[0].href);
e.preventDefault();
});
});
and it works.
Upvotes: 0
Reputation: 300
I believe you need to add a return false;
at the end of your javascript function. In order for the link not to execute its original functionality of reference the main page to its href.
Hope this helps.
Cheers,
Dan
Upvotes: 1