A small javaScript utility to make sure that window.open
actually opens same domain windows at the size you requested.
Opening a window with a set viewport is notoriously difficult across all the different browsers, and they usually end up 20px or so too short.
It opens a new window as per usual, but then checks the innerHeight
and innerWidth
match the initial request, and adjusts the window size accordingly.
Unfortunately it will not run cross domain due to same origin security policies.
npm install window-opener --save
yarn add window-opener
bower install window-opener --save
Include the file in your project.
<script type="text/javascript" src="window-opener.js"></script>
<script type="text/javascript" src="window-opener.js"></script>
<script>
windowOpener.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
</script>
define(['path/to/window-opener'], function (windowOpener) {
windowOpener.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
});
This is exactly the same as window.open
Wraps the native window.open
method with windowOpener.open
, meaning you don't have to update any of your code.
windowOpener.wrap();
...
// all window.open calls now run via windowOpener.open
window.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
Restores the native window.open
method