In my Ionic app, I need to open the login page of a third-party service in a new browser window. When the login succeeds, the third-party login page will fire a redirect request with a parameter I need to capture. Once I have the parameter, I need to effectively cancel the URL load request.
I have a native iOS implementation of this that opens the third-party login page in a web view and then uses the web view's shouldStartLoadWithRequest:requestNaviationType: method to capture the request and parse the parameters. Based on the parsed result, it either loads the URL or cancels the request.
The Cordova InAppBrowser function will allow me to open a URL in a new window, and it allows me to listen to the loadstart event. But how can I prevent the redirect URL from loading?
inAppBrowserRef = cordova.InAppBrowser.open(url, target, options);
inAppBrowserRef.addEventListener('loadstart', loadStartCallBack);
function loadStartCallBack() {
if ( cancelConditionMet ) {
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
}