I am using Ionic with React or Capacitor I want close my InAppBrowser for any particular URL ....Thanks in advance.
// open InAppBrowser w/out the location bar
var ref = window.open('http://myloginapp.com', '_self');
// attach listener to loadstart
ref.addEventListener('loadstart', function(event) {
var urlSuccessPage = "http://myloginapp/success/";
if (event.url == urlSuccessPage) {
ref.close();
}
});
Take a look at examples in the plugin documentation.
It would seem that loadstart
event doesn't contain a URL param. Try using beforeloadCallBack
to detect the URL that's being loaded.
For example:
ref.addEventListener('beforeload', function(params, callback) {
var urlSuccessPage = "http://myloginapp/success/";
if (params.url === urlSuccessPage ) {
ref.close();
} else {
callback(params.url);
}
});
Also, make sure window.open()
is indeed referencing InAppBrowser. You might need to use window.cordova.InAppBrowser.open()
.