Skip to content

Instantly share code, notes, and snippets.

@jrop
Created April 11, 2014 18:35
Show Gist options
  • Save jrop/10490670 to your computer and use it in GitHub Desktop.
Save jrop/10490670 to your computer and use it in GitHub Desktop.
cordova-in-app-browser-utilities
/*
* Utilities for managing popups easily in Apache Cordova
* Use like:
*
* ...
* <script src="path/to/cordova.js"></script>
* <script src="path/to/this/file/iab.js"></script>
* ...
*
* Also, be sure that the InAppBrowser plugin is
* enabled for your Cordova application
*/
window.iab = {
open: function(url) {
var w = window.open(url, '_blank', 'location=no');
function cleanup() {
w.removeEventListener('loadstart', loadStart);
w.removeEventListener('exit', exit);
w = null;
}
function loadStart(e) {
var url = /\/iab\/js\/close$/;
if (!url.test(e.url)) return;
w.close();
cleanup();
}
function exit(e) {
cleanup();
}
w.addEventListener('loadstart', loadStart);
w.addEventListener('exit', exit);
return w;
},
/*
* Closes the current window
*/
close: function() {
window.location = '/iab/js/close';
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment