https://github.com/mattbryson/window-opener
A small utility that fixes window.open so the resulting window is the size you actually requested
https://github.com/mattbryson/window-opener
browser javascript javascript-plugin
Last synced: 7 months ago
JSON representation
A small utility that fixes window.open so the resulting window is the size you actually requested
- Host: GitHub
- URL: https://github.com/mattbryson/window-opener
- Owner: mattbryson
- License: other
- Created: 2018-09-18T11:54:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-09-18T14:13:55.000Z (over 7 years ago)
- Last Synced: 2025-05-25T07:40:50.160Z (10 months ago)
- Topics: browser, javascript, javascript-plugin
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Window Opener
A small javaScript utility to make sure that `window.open` actually opens **same domain** windows at the size you requested.
### Why
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.
### How
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.
### Wont
Unfortunately it will not run cross domain due to same origin security policies.
## Installation
### NPM
````bash
npm install window-opener --save
````
### YARN
````bash
yarn add window-opener
````
### Bower
````bash
bower install window-opener --save
````
### Manual
Include the file in your project.
````html
````
## Usage
### Browser
````html
windowOpener.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
````
### Require
````javascript
define(['path/to/window-opener'], function (windowOpener) {
windowOpener.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
});
````
## Demo
[A super simple demo](https://mattbryson.github.io/window-opener/demo/index.html)
## API
### open( url, windowName, [windowFeatures] )
This is exactly the same as `window.open`
### wrap()
Wraps the native `window.open` method with `windowOpener.open`, meaning you don't have to update any of your code.
````javascript
windowOpener.wrap();
...
// all window.open calls now run via windowOpener.open
window.open('http://www.domain.com', '_blank', 'width=500px, height=500px');
````
### unWrap()
Restores the native `window.open` method