I have the following html/jquery code, that is supposed to open a new page, but is opening 2:
$('.div_link').live('click', function(){
window.open($(this).attr('url'), '_blank', 'toolbar=no,resizable=yes,location=yes,menubar=yes');
});
<div class="div_link" url="/test/as/8888888-888">8888888-888</div>
So, everything is working fine, except that I get two new windows with the exact same content in them. I've seen people suggesting that there was something to do with returning false in the onclick event, but I don't think it's the case here.
Also, I've tried to do something like:
var handler = window.open(...);
Edit: Tried something alike what gdoron suggested but then it doesn't open any window, and the click event isn't fired.
$('div.div_link').on({
click: function(){
window.open($(this).attr('url'), '_blank','toolbar=no,resizable=yes,location=yes,menubar=yes');
return false;
}});
What can cause this:
div_link and the event bubbles.Regarding the last option, use on instead of the deprecated(1.7)-deleted (1.9) live function:
$('#containerId').on('click', '.div_link', function(){
window.open($(this).attr('url'), '_blank', 'toolbar=no,resizable=yes,location=yes,menubar=yes');
return false;
});
You can stop the bubbling in on unlike with live.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With