Search code examples
androidioscordovadialogcordova-plugins

Close all open cordova Dialogs


I'm using the plugin cordova-plugin-dialogs on a hybrid application and I need to close all open dialogs triggered by the navigator.notification.confirm method, programmatically. I tried to click on a hidden element to do this (since on runtime if I click outside the dialog this works) but no success. Is there a way to do this using javascript or some cordova capabilities?


Solution

  • I had a requirement for this myself a while back. The official version of cordova-plugin-dialogs doesn't currently support this functionality so I forked it and implemented my own solution.

    My fork is a bit out-of-date with respect to the official repo, but it still does the job for me. If you want to give it a try, install my fork:

    cordova plugin add https://github.com/dpa99c/cordova-plugin-dialogs
    

    Then you can dismiss all currently open dialogs with:

    navigator.notification.dismissAll();
    

    Or dismiss the most recently opened dialog with:

        navigator.notification.dismissPrevious();
    

    I should probably put this together in a pull request to get it merged into the official version of the plugin.