Search code examples
androidcordovaionic-frameworkinappbrowser

Ionic - toast message not working inside 'loaderror' eventlistner function of inappbrowser


I'm trying to show toast message when the given url fails to load in inappbrowser, this is my code

function BrowserLoadError(event) {
        browser.close();
        loading.dismiss();
        this.toast.show("Can't Load the app", '3000', 'center').subscribe(
            toast => {
                console.log(toast);
            }
        );
        //alert("This App can't be reached now");
    }

but however its not working, the toast message is not showing, but it is displaying when we are calling from anyother place other than eventlistner function.

how to make it work within the function?

This is my full code

urlLink(data, target, options): void {
    let loading = this.loadingCtrl.create({
        spinner: 'bubbles',
        content: 'Processing',
        duration: 5000
    });

    let browser = cordova.InAppBrowser.open(data, target, options);

    browser.hide();
    loading.present();
    browser.addEventListener('loaderror', BrowserLoadError);

    function BrowserLoadError(event) {
        browser.close();
        loading.dismiss();
        this.toast.show("Can't Load the app", '3000', 'center').subscribe(
            toast => {
                console.log(toast);
            }
        );
        //alert("This App can't be reached now");
    }
}

Solution

  • In the mean time i too found the issue and fixed like this

    let toast = new Toast();
    toast.show("This App can't be launched now", '5000', 'bottom').subscribe(
        toast => {
            console.log(toast);
        }
    );