Skip to content

Files

Latest commit

888a452 · Feb 11, 2013

History

History
26 lines (18 loc) · 890 Bytes

README.md

File metadata and controls

26 lines (18 loc) · 890 Bytes

Jailor

Allows web applications to register conditions under which an user will be asked to confirm exiting the page.

It is a simple wrapper over onbeforeunload (demo) that allows to add multiple conditions easily.

Example

var car = {
	wheelsCount: 2
}

instructionsDiv.textContent = 'Fix the car!';

Jailor.lock(function() {
	if (car.wheelsCount != 4) {
		return 'The car is expected to have 4 wheels, not ' + car.wheelsCount + '!';	// return an error-description string to ask confirmation from the user
	}	// return anything else than a string (or nothing) to allow the user to leave the page without any question
});

Notes

Jailor respects any previous onbeforeunload handler already in place, and will add it as a condition.