Ios 电话间隔确认警报

Ios 电话间隔确认警报,ios,cordova,alert,confirmation,Ios,Cordova,Alert,Confirmation,我试着把下面的代码放到一个html中并运行它,然后我把它上传到我的服务器上,在我的iPhone中打开Safari浏览器中的链接,然后点击Show Confirm,没有弹出窗口!有人能帮忙吗 <!DOCTYPE html> <html> <head> <title>Notification Example</title> <script type="text/javascript" charset="utf-8"

我试着把下面的代码放到一个html中并运行它,然后我把它上传到我的服务器上,在我的iPhone中打开Safari浏览器中的链接,然后点击Show Confirm,没有弹出窗口!有人能帮忙吗

<!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>
    <script type="text/javascript" charset="utf-8" src="http://mobile-web-development-with-phonegap.eclipselabs.org.codespot.com/svn-history/r99/trunk/com.mds.apg/resources/phonegap/js/phonegap-1.0.0.js"></script>
    <script type="text/javascript" charset="utf-8">
        // Wait for PhoneGap to load
        document.addEventListener("deviceready", onDeviceReady, false);
        // PhoneGap is ready        
        function onDeviceReady() {
            // Empty
        }
        // process the confirmation dialog result
        function onConfirm(button) {
            alert('You selected button ' + button);
        }
        // Show a custom confirmation dialog
                function showConfirm() {
            navigator.notification.confirm(
            'You are the winner!',  // message
            onConfirm,              // callback to invoke with index of button pressed
            'Game Over',            // title
            'Restart,Exit'          // buttonLabels
        );
        }
    </script>
  </head>
  <body>
    <p><a href="#" onclick="showConfirm(); return false;">Show Confirm</a></p>
  </body>
</html>

通知示例
//等待PhoneGap加载
文件。添加的监听器(“deviceready”,OnDeviceraddy,false);
//PhoneGap已经准备好了
函数ondevicerady(){
//空的
}
//处理确认对话框结果
函数onConfirm(按钮){
警报(“您选择的按钮”+按钮);
}
//显示自定义确认对话框
函数showConfirm(){
navigator.notification.confirm(
“你是赢家!”,//留言
onConfirm,//要在按下按钮索引时调用的回调
“游戏结束了”,//标题
'重新启动,退出'//按钮标签
);
}


您正在使用的代码(
navigator.notification.confirm
)是专门针对移动平台的,它将在PhoneGap移动应用程序中运行。如果您想在将对话框/确认消息编译到应用程序之前测试浏览器上的对话框/确认消息,我建议使用混合方法检测应用程序的环境,并使用本机
confirm(message)
或PhoneGap特定的通知API。下面是一个为我工作的示例对象:

/**
 * The object encapsulates messaging functionality to work both in PhoneGap and 
 * browser environment. 
 * @author Zorayr Khalapyan
 * 
 */
var MessageDialogController = (function () {

    var that = {};

    /**
     * Invokes the method 'fun' if it is a valid function. In case the function
     * method is null, or undefined then the error will be silently ignored.
     *
     * @param fun  the name of the function to be invoked.
     * @param args the arguments to pass to the callback function.
     */
    var invoke = function( fun, args ) {
        if( fun && typeof fun === 'function' ) {
            fun( args );
        }
    };

    that.showMessage = function( message, callback, title, buttonName ) {

        title = title || "DEFAULT_TITLE";
        buttonName = buttonName || 'OK';

        if( navigator.notification && navigator.notification.alert ) {

            navigator.notification.alert(
                message,    // message
                callback,   // callback
                title,      // title
                buttonName  // buttonName
            );

        } else {

            alert( message );
            invoke( callback );
        }

    };

    that.showConfirm = function( message, callback, buttonLabels, title ) {

        //Set default values if not specified by the user.
        buttonLabels = buttonLabels || 'OK,Cancel';
        var buttonList = buttonLabels.split(',');

        title = title || "DEFAULT TITLE";

        //Use Cordova version of the confirm box if possible.
        if (navigator.notification && navigator.notification.confirm) {

                var _callback = function (index) {
                    if ( callback ) {
                        //The ordering of the buttons are different on iOS vs. Android.
                        if(navigator.userAgent.match(/(iPhone|iPod|iPad)/)) {
                            index = buttonList.length - index;
                        }
                        callback( index == 1 );
                    }
                };

                navigator.notification.confirm(
                    message,      // message
                    _callback,    // callback
                    title,        // title
                    buttonLabels  // buttonName
                );

        //Default to the usual JS confirm method.
        } else {
            invoke( callback, confirm( message ) );
        }

    };

    return that;

})();

希望这有帮助!如果你有任何问题,请告诉我

您正在尝试从浏览器使用Phonegap API。只有当您使用Phonegap制作本机应用程序时,它们才会起作用。确保您理解什么是Phonegap。我应该将您的代码插入到哪里?我使用的是Phonegap html。你能上传一个示例模板文件吗?这样我就可以测试和学习了。把代码放在一个JavaScript文件中,然后通过标签将它导入你的html页面。您应该能够通过调用方法来调用这些方法,即
MessageDialogController.showConfirm(“Hello World”)。我确实将js导入到html中,我在弹出窗口调用MessageDialogController时遇到问题。showConfirm(“Hello World”)你能提供一个html代码示例吗?除了confirm回调外,效果非常好!我在
test=MessageDialogController.showConfirm(“Confirm”)console.log(test)
上未定义。。。有什么想法吗?好的。。所以我发现phonegap控件与回调一起工作。这可以使用
MessageDialogController.showConfirm(“消息”,函数(数据){console.log(数据)},'OK,Cancel','Title')