promise-window
Lightweight wrapper around window.open() that adds Promise and postMessage support
![Dependency Status](http://img.shields.io/gemnasium/amercier/promise-window.svg?style=flat-square)
![PromiseWindow](https://cloud.githubusercontent.com/assets/1246795/6099683/cdd9e59c-afb3-11e4-92a3-f1688990984f.png)
Live example
Installation
Bower (recommended)
bower install promise-window --save-dev
NPM
npm install promise-window --save-dev
Manuall installation
Grab a copy of promise-window
(development version).
Usage
The simplest way to use PromiseWindow is to use the PromiseWindow.open
convenience method:
PromiseWindow.open('http://popup.html').then(
function(data) {
},
function(error) {
switch(error) {
case 'closed':
break;
case 'my-custom-message':
break;
}
}
);
opener.postMessage({ result: 'yeah' }, location.origin);
opener.postMessage({ error: 'my-custom-message' }, location.origin);
Advanced usage
Instanciating the PromiseWindow
prototype gives you more control. The
following example shows how to close the window after 30 seconds.
var promiseWindow = new PromiseWindow('http://popup.html'),
timeout = window.setTimeout(function() {
promiseWindow.close();
}, 30000);
promiseWindow.open().then(
function(data) {
window.clearTimeout(timeout);
},
function(error) {
window.clearTimeout(timeout);
}
);
See API Documentation
for more information about the PromiseWindow
prototype.
Authors
Versioning
This library follows Semantic Versioning
Want to help?
Please do! We are always looking to improve this component. Please see our
Contribution Guidelines
on how to properly submit issues and pull requests.
Legal
Alex Mercier © 2015
Licensed under the MIT license