
So now most browsers try to block popups and protect the user. A bad page could open tons of popup windows with ads. In the past, evil sites abused popups a lot.
A popup can navigate (change URL) and send messages to the opener window. So opening a popup from a third-party, non-trusted site is safe. A popup is a separate window which has its own independent JavaScript environment. for OAuth authorization (login with Google/Facebook/…), because: Still, there are tasks where popups are still used, e.g. So, popups is not something we use everyday.Īlso, popups are tricky on mobile devices, that don’t show multiple windows simultaneously. As of now, there are other ways to do that: we can load content dynamically with fetch and show it in a dynamically generated. The initial idea was to show another content without closing the main window. Most modern browsers are configured to open url in new tabs instead of separate windows. You need to know that window.open has a return value, and that value may be null if the action failed.…And it will open a new window with given URL. The _blank bit helps for the mailto redirection to work on mobile, btw.Īs a good practice I think it is a good idea to test if a popup was blocked and take action in case.
I actually use this solution for a mailto redirection, and it works on all my browsers (windows 7, Android). Examples:Ī) An external HTML page: replace the above line with var importantStuff = window.open('', '_blank') ī) Text: add the following line below the above one: ('Loading preview.') įill it with content when ready (when the AJAX call is returned, for instance) = '' Īlternatively, you could close the window here if you don't need it after all ( if ajax request fails, for example - thanks to for the comment): importantStuff.close() Optional: add some "waiting" info message. (Enrich the call to window.open with whatever additional options you need.) Immediately create a blank popup on user action var importantStuff = window.open('', '_blank') Based on Jason Sebring's very useful tip, and on the stuff covered here and there, I found a perfect solution for my case: