diff --git a/src/windows/InAppBrowserProxy.js b/src/windows/InAppBrowserProxy.js index 1d17bc5..5842212 100644 --- a/src/windows/InAppBrowserProxy.js +++ b/src/windows/InAppBrowserProxy.js @@ -120,14 +120,14 @@ var IAB = { popup.style.width = "100%"; popup.style.height = "100%"; + // start listening for navigation events + attachNavigationEvents(popup, win); + if (isWebViewAvailable) { strUrl = strUrl.replace("ms-appx://", "ms-appx-web://"); } popup.src = strUrl; - // start listening for navigation events - attachNavigationEvents(popup, win); - browserWrap.appendChild(popup); } }, diff --git a/tests/tests.js b/tests/tests.js index 4a9e5ef..1587b99 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -29,11 +29,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { function doOpen(url, target, params, numExpectedRedirects) { numExpectedRedirects = numExpectedRedirects || 0; console.log("Opening " + url); - var iab = window.open(url, target, params); - if (!iab) { - alert('window.open returned ' + iab); - return; - } + var counts; var lastLoadStartURL; var wasReset = false; @@ -48,6 +44,17 @@ exports.defineManualTests = function (contentEl, createActionButton) { } reset(); + var iab = window.open(url, target, params, { + loaderror: logEvent, + loadstart: logEvent, + loadstop: logEvent, + exit: logEvent + }); + if (!iab) { + alert('window.open returned ' + iab); + return; + } + function logEvent(e) { console.log('IAB event=' + JSON.stringify(e)); counts[e.type]++; @@ -85,10 +92,6 @@ exports.defineManualTests = function (contentEl, createActionButton) { } } } - iab.addEventListener('loaderror', logEvent); - iab.addEventListener('loadstart', logEvent); - iab.addEventListener('loadstop', logEvent); - iab.addEventListener('exit', logEvent); return iab; } diff --git a/www/inappbrowser.js b/www/inappbrowser.js index 4211563..a85f27e 100644 --- a/www/inappbrowser.js +++ b/www/inappbrowser.js @@ -77,7 +77,7 @@ InAppBrowser.prototype = { } }; -module.exports = function(strUrl, strWindowName, strWindowFeatures) { +module.exports = function(strUrl, strWindowName, strWindowFeatures, callbacks) { // Don't catch calls that write to existing frames (e.g. named iframes). if (window.frames && window.frames[strWindowName]) { var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open'); @@ -86,6 +86,12 @@ module.exports = function(strUrl, strWindowName, strWindowFeatures) { strUrl = urlutil.makeAbsolute(strUrl); var iab = new InAppBrowser(); + + callbacks = callbacks || {}; + for (var callbackName in callbacks) { + iab.addEventListener(callbackName, callbacks[callbackName]); + } + var cb = function(eventname) { iab._eventHandler(eventname); };