I have a div element. The div is an icon. When you click on this icon is triggered a form submit. On the form submit there are some calculations and with the result of those calculations a new tab is opened.
I use the "window.open(url, '_blank');"
But in safari and chrome this new tab is seen as a popup and is blocked.
I tried to create a hidden a href and to trigger click so it will open the page in new tab, but it doesn't work.
Any idea how to fix this?
EDIT - SOLUTION FOUND
You need to add the window.open on a click event inside an $.ajax success method. In this way it will work.
$('#myButton').click(function () {
var redirectWindow = window.open('http://google.com', '_blank');
$.ajax({
type: 'POST',
url: '/echo/json/',
success: function (data) {
redirectWindow.location;
}
});
});
http://jsfiddle.net/safeeronline/70kdacL4/1/
you need to call window.open as a direct result of a onclick event (user event)... you can't do something before async, and then on a result of that do the window.open
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