dialog.js - Live Demo

Note:

To see the full documentation, please refer to the wiki.

A shorter and essential reference is also available at the beginning of the dialog.js file.


First example

Basic alert message.

<script type="text/javascript">
dialogSettings = {
	defType: "confirm",
	defTitle: "Conferma",
	defContent: "Contenuto non impostato",
	okText: "Accetta",
	continueText: "Continua",
	cancelText: "Annulla"
};
</script>

<button onclick="dialog()">Try it</button>
In action:

Second example

Use of arguments.

<script type="text/javascript">
var parameters = {
	type: "prompt",
	title: "Example",
	content: "What's your name?",
}
</script>

<button onclick="dialog(parameters)">Try it</button>
In action:

Third example

Advanced use: using chaining and data carrying.

<script type="text/javascript">
function check(box1) {
	if (box1.action) {
		box1.data.name = box1.value != "" ? box1.value : "Unnamed";
		dialog({
			type: "confirm",
			content: "Do you want your name printed on a message?",
			data: box1.data,
		})
		.then(function(box2) {
			if (box2.action) {
				dialog({
					//NB: default type is alert, so we don't need to specify it
					title: "Print out",
					content: "Hello "+box2.data.name+"\nFoo: "+box2.data.foo
				});
			}
		});
	}
}

var parameters = {
	type: "prompt",
	title: "Example",
	content: "What's your name?"",
	data: {foo: "bar"}
};
</script>

<button onclick="dialog(parameters).then(check)">Try it</button>
In action: