I've build a web page that let's you select a page name from a drop down list and then transfers the browser to that page. The code that does the transfer is
if (url){ window.open(url, '_blank'); }
where "url" is the page selected.
A console log just before the window.open line prints something like:
executing: window.open(http://www.mywebsite.com/44/threats.html, '_blank')
and then the browsers opens the page in a new tab.
This works fine on Windows 7 for all the browsers, including Safari.
On an iMac it works for Firefox but not for Safari.
Does anyone know why iMac/Safari won't do this?
Safari blocks any window. open() function during an async call to provide "better" security. If you are using window. open() anyways inside an async call, Safari users will get a popup with the message, that a popup gets blocked.
Sometimes Safari caches can cause strange browser behavior like displaying a “Can't open page” error message. Emptying the browser caches and site data can often remedy this issue.
Safari is blocking any call to window.open() which is made inside an async call.
The solution that I found to this problem is to call window.open before making an asnyc call and set the location when the promise resolves.
var windowReference = window.open(); myService.getUrl().then(function(url) { windowReference.location = url; });
To use window.open() in safari you must put it in an element's onclick event attribute.
For example: <button class='btn' onclick='window.open("https://www.google.com", "_blank");'>Open Google search</button>
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