Windows Phone and PhoneGap – Article #5 – Displaying MessageBox in PhoneGap – Part 2
In my previous post , i explained about displaying MessageBox in Windows Phone using PhoneGap that had only the OK button .
In this blog post , i will show you how to create a MessageBox with confirmation ( OK and Cancel ) using PhoneGap .
If you were doing a Windows Phone Development using Silverlight and C# , you would use the below code to display the messagebox with confirmation .
MessageBox.Show("Do you want to continue ?", "Confirmation", MessageBoxButton.OKCancel);
The MessageBox.Show returns MessageBoxResult .
The PhoneGap provides the navigator.notification.confirm method to do the same .
You could use the notification.confirm method to display a Confirmation Dialog in Windows Phone using PhoneGap .
navigator.notification.confirm accept the following parameters
- Message – Dialog message to be displayed on the messagebox
- callback function – function to be invoked when the dialog is dismissed
- Title – Title to be displayed on the Dialog . Note that by default this is “Alert” as seen in the above screenshot
- Names for Button – Name or caption for the button to be displayed .
Since MessageBox.Show has only 2 MessageBoxButton’s OK and OK, Cancel , you will notice that the Names for Button will always be OK and Cancel in Windows Phone irrespective of what is specified
function Button1_onclick()
{
navigator.notification.confirm('Do you Want to Continue ?',null, 'Confirmation'
Now , if you want to know which button was clicked , include the function in the 2nd parameter of the confirm method like the below sample code .
<script type="text/javascript">
function selectedbutton(button)
{
navigator.notification.alert('You clicked ' + button.toString());
}
function Button1_onclick()
{
navigator.notification.confirm('Do you Want to Continue ?', selectedbutton, 'Confirmation');
}
</script>

