简体   繁体   中英

How can I get the Cordova navigator.notification.confirm dialog box to trigger inappbrowser?

I have a web link that doesn't play nice with inappbrowser on Cordova 3.4.0 (it doesn't load - it's a script from a website) so I want to use the native mobile browser (iOS and Android) to view the site instead of inappbrowser. This in itself is no problem. I just simply set inappbrowser to _system.

My problem arises when I try to throw a notification dialog into the mix to warn the end user that they are about to be taken out of the app and into their native browser. For this I am trying to use Cordovas navigator.notification.confirm plugin. This should show a dialog box with option buttons (in this case ok and cancel) when the user clicks on the original link. Then, when ok is pressed, the dialog calls the function that runs the inappbrowser or if cancel is pressed the dialog closes and returns the user to the app.

Whats happening is that the dialog box is showing up just fine, however, both the ok and cancel buttons simply close the dialog box and don't launch the function that should in turn launch the native web browser. Here is my javascript:

<script type="text/javascript" charset="utf-8">

        function payrent(){
            navigator.notification.confirm(
            'You are about to leave this app and open your default web browser. Continue?', 
            payrent1(),
            'Leave App?',
            ['Ok','Cancel']
            );
        }
        </script>
    <script type="text/javascript" charset="utf-8">

        function payrent1(buttonIndex){
        if (buttonIndex==1){
            window.open('https://tenants.saffronhousing.co.uk/scripts/cgiip.exe/WService=live-openaccess/ibsxmlpr.p?docid=login', '_system', 'location=no');
            }
        }
        </script>

Any ideas on what's going on? I have tweaked everything I can think of in the code and the only other outcome I can get is that the dialog box shows briefly and then inappbrowser launches anyway regardless of the fact no buttons have been pressed!

Any help would be greatly appreciated.

Just remove the brackets from the callback argument:

function payrent() {
    navigator.notification.confirm(
        'You are about to leave this app and open your default web browser. Continue?', 
        payrent1, // <-- no brackets
        'Leave App?',
        ['Ok','Cancel']
    );
}

With the brackets the function is called immediately and its result ( undefined ) is passed to the confirm function as callback.
Without the brackets you pass the function itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM