Skip to content
Guillaume Gendre edited this page Apr 29, 2019 · 10 revisions

We think that asking something simple to the user should be simple and should shown in a way the user is used to.

So Cobalt Alerts are shown the native way. No web "pop-in".

You can choose title, message, buttons and add a callback to know what the user wants !

Showing a native alert from the Web side

cobalt.alert(options)

Use this to show a native alert to your user and to be warned when the user replies.

options is an object. Here are the available options :

  • title : The alert title. write something short.
  • message : the detailed message to show in the alert text.

Both title and message are optional, but at least one should be set. If title is undefined, the message is used as the title.

  • buttons : A strings array of the buttons texts. Cobalt will add a button per string. 3 buttons is the max.

If you do not set any button, a solo button with text "Ok" will be added to close the alert.

  • callback : An optional javascript function to call when alert is closed. This function will receive the index of the touched button, starting at 0.

  • cancelable : (Android only) an optional boolean that defaults to false. On android, the user usually can close the alert by tapping into the background or pressing the "back" button. In Cobalt Android, we set the default cancelable to false to match with the iOS style. But if you want to allow them to cancel with a tap in the background or with the back button, you can! just set cancelable to true.

Example

//A simple alert
cobalt.alert({ 
	title : "Hello World !", 
	message : "Thank you for being there !", 
});

//An alert with a callback
cobalt.alert({ 
	title : "Do you want some tea?", 
	buttons : ["Yes", "No"], 
	callback:function(data){ 
		cobalt.log('user clicked button #' +data.index) 
	}
});
Clone this wiki locally