/jquery.warnunload.js

Warn the user if they made changes that are not saved before letting them browse away.

Primary LanguageJavaScript

jquery.warnunload.js

jquery.warnunload.js is a jQuery plugin that allows you to simply insert warnings to the user if they made changes to a page's inputs and then browse away before clicking save or update. This is done via the "onbeforeunload" event.

Usage

$.warnUnload({
      message:"Are you sure you want to leave this page without saving?", 
      urls:["/Property/Edit","/Property/MoreInformation"],
      ignore:["#Continue","#Done","#Cancel","#Delete"] 
    });

Demo

You can check out the demo in the ./demo directory.

Options

Option Type Default Description
message string "Are you sure you want to leave this page?" Message to display in confirm window (not supported in all browsers)
urls array [] Array of urls to track input changes and warn user if unsaved changes will be lost. Only partial urls are needed as a check for location.href.indexOf(url) is done. If current url is not listed, plugin does not warn user if changes will be lost.
ignore string ".ignore-warn" Comma-seperated list of jQuery selector queries to ignore warning the user. e.g. ".ignore, #save, input[type='submit']"

Does it work in all browsers?

Browser Version(s) Tested? Issues
Internet Explorer 6 Not tested
Internet Explorer 7 Not tested
Internet Explorer 8 Tested
Internet Explorer 9 Tested
Internet Explorer 10 Not tested
Firefox 13.0.1 Tested
Chrome 20+ Tested
Opera 11.61 Failed Opera did not stop and warn user at all. Not supported as of yet.
Safari 5.1.7 Tested

Depenencies?

Just jQuery, tested with jQuery 1.7.2.