Created
April 11, 2014 18:35
-
-
Save jrop/10490670 to your computer and use it in GitHub Desktop.
cordova-in-app-browser-utilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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