Back to Demos List

GSW Browser - Dialogs and Alerts

This page demonstrates the ability to send native android dialogs and alerts from events within the browser.



Status: Not ready


About This Demo

This demo is using the cordova-plugin-device plugin. For more information click here:

	
		var GSW = GSW || {};
GSW.Tests = GSW.Tests || {};


GSW.Tests.onDeviceReady = function() {
	// Cordova is now initialized.

	console.log('Now running cordova-' + cordova.platformId + '@' + cordova.version);

	GSW.Tests.dialogAlert = function() {
		var message = "The best Android (Telnet, SSH, and Web) client!";
		var title = "ALERT: GSW ConnectBot";
		var buttonName = "Close Alert";
		navigator.notification.alert(message, alertCallback, title, buttonName);

		function alertCallback() {
			console.log("Alert is Dismissed!");
		}
	}
	GSW.Tests.dialogConfirm = function() {
		var message = "Is GSW ConnectBot the solution for you?";
		var title = "CONFIRM";
		var buttonLabels = "YES,YES";
		navigator.notification.confirm(message, confirmCallback, title, buttonLabels);

		function confirmCallback(buttonIndex) {
			console.log("You clicked " + buttonIndex + " button!");
		}
	}
	GSW.Tests.dialogPrompt = function() {
		var message = "Am I Prompt Dialog?";
		var title = "PROMPT";
		var buttonLabels = ["YES", "NO"];
		var defaultText = "Default"
		navigator.notification.prompt(message, promptCallback,
			title, buttonLabels, defaultText);

		function promptCallback(result) {
			console.log("You clicked " + result.buttonIndex + " button! \n" +
				"You entered " + result.input1);
		}
	}
	GSW.Tests.dialogBeep = function() {
		var times = 2;
		navigator.notification.beep(times);
	}
	document.getElementById("dialogAlert").addEventListener("click", GSW.Tests.dialogAlert);
	document.getElementById("dialogConfirm").addEventListener("click", GSW.Tests.dialogConfirm);
	document.getElementById("dialogPrompt").addEventListener("click", GSW.Tests.dialogPrompt);
	document.getElementById("dialogBeep").addEventListener("click", GSW.Tests.dialogBeep);
}
document.addEventListener('deviceready', GSW.Tests.onDeviceReady, false);