Gathering detailed insights and metrics for jquery.are-you-sure
Gathering detailed insights and metrics for jquery.are-you-sure
Gathering detailed insights and metrics for jquery.are-you-sure
Gathering detailed insights and metrics for jquery.are-you-sure
@types/jquery.are-you-sure
TypeScript definitions for jquery.are-you-sure
@ryancavanaugh/jquery.are-you-sure
Type definitions for jquery.are-you-sure.js from https://www.github.com/DefinitelyTyped/DefinitelyTyped
retyped-jquery.are-you-sure-tsd-ambient
TypeScript typings for jquery.are-you-sure
A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
npm install jquery.are-you-sure
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (99.14%)
HTML (0.86%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
509 Stars
94 Commits
142 Forks
30 Watchers
4 Branches
13 Contributors
Updated on Apr 14, 2025
Latest Version
1.9.0
Package Id
jquery.are-you-sure@1.9.0
Size
12.19 kB
NPM Version
5.5.1
Node Version
6.11.4
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Version: 1.9
Are-you-sure (jquery.are-you-sure.js
) is simple light-weight "dirty
form" JQuery Plugin for modern browsers. It helps prevent users from losing
unsaved HTML Form changes by promoting the user to save/submit.
It's simple to use. Just add the following line to your page's ready function:
1$('form').areYouSure();
Are-you-sure is a minimal plugin for modern browsers. There are plenty of "dirty forms" implementations out there, however they all seemed very heavyweight and over-engineered...! Most were written some time back and contain many 'hacks' to support legacy browsers, and/or rely on other fat dependencies such as FaceBox or jQueryUI. Are-you-sure solves this by doing this simple task in the simplest possible way.
Are-you-sure is as simple as it gets:
onBeforeUnload
to detect all page/browser exit events.###Basic Usage
1 2$(function() { 3 4 // Enable on all forms 5 $('form').areYouSure(); 6 7 // Enable on selected forms 8 $('form.dirty-check').areYouSure(); 9 10 // With a custom message 11 $('form').areYouSure( {'message':'Your profile details are not saved!'} ); 12 13}
To ignore selected fields from the dirtyness check:
1 <form id="myForm" name="myform" action="/post" method="post"> 2 3 Field 1: (checked) <input type="text" name="field1"> <br /> 4 Field 2: (ignored): <input type="text" name="field2" data-ays-ignore="true"> <br /> 5 Field 3: (ignored): <input type="text" name="field3" class="ays-ignore"> <br /> 6 7 <input type="submit" value="Submit"> 8 9 </form>
###Advanced Usage
1 2$(function() { 3 4 /* 5 * Make Are-You-Sure "silent" by disabling the warning message 6 * (tracking/monitoring only mode). This option is useful when you wish to 7 * use the dirty/save events and/or use the dirtyness tracking in your own 8 * beforeunload handler. 9 */ 10 $('form').areYouSure( {'silent':true} ); 11 12 /* 13 * Dirtyness Change Events 14 * Are-You-Sure fires off "dirty" and "clean" events when the form's state 15 * changes. You can bind() or on(), these events to implement your own form 16 * state logic. A good example is enabling/disabling a Save button. 17 * 18 * "this" refers to the form that fired the event. 19 */ 20 $('form').on('dirty.areYouSure', function() { 21 // Enable save button only as the form is dirty. 22 $(this).find('input[type="submit"]').removeAttr('disabled'); 23 }); 24 $('form').on('clean.areYouSure', function() { 25 // Form is clean so nothing to save - disable the save button. 26 $(this).find('input[type="submit"]').attr('disabled', 'disabled'); 27 }); 28 29 /* 30 * It's easy to test if a form is dirty in your own code - just check 31 * to see if it has a "dirty" CSS class. 32 */ 33 if ($('#my-form').hasClass('dirty')) { 34 // Do something 35 } 36 37 /* 38 * If you're dynamically adding new fields/inputs, and would like to track 39 * their state, trigger Are-You-Sure to rescan the form like this: 40 */ 41 $('#my-form').trigger('rescan.areYouSure'); 42 43 /* 44 * If you'd like to reset/reinitialize the form's state as clean and 45 * start tracking again from this new point onwards, trigger the 46 * reinitalize as follows. This is handy if say you've managing your 47 * own form save/submit via asyc AJAX. 48 */ 49 $('#my-form').trigger('reinitialize.areYouSure'); 50 51 /* 52 * In some situations it may be desirable to look for other form 53 * changes such as adding/removing fields. This is useful for forms that 54 * can change their field count, such as address/phone contact forms. 55 * Form example, you might remove a phone number from a contact form 56 * but update nothing else. This should mark the form as dirty. 57 */ 58 $('form').areYouSure( {'addRemoveFieldsMarksDirty':true} ); 59 60 /* 61 * Sometimes you may have advanced forms that change their state via 62 * custom JavaScript or 3rd-party component JavaScript. Are-You-Sure may 63 * not automatically detect these state changes. Examples include: 64 * - Updating a hidden input field via background JS. 65 * - Using a [rich WYSIWYG edit control](https://github.com/codedance/jquery.AreYouSure/issues/17). 66 * One solution is to manually trigger a form check as follows: 67 */ 68 $('#my-form').trigger('checkform.areYouSure'); 69 70 /* 71 * As an alternative to using events, you can pass in a custom change 72 * function. 73 */ 74 $('#my-adv-form').areYouSure({ 75 change: function() { 76 // Enable save button only if the form is dirty. i.e. something to save. 77 if ($(this).hasClass('dirty')) { 78 $(this).find('input[type="submit"]').removeAttr('disabled'); 79 } else { 80 $(this).find('input[type="submit"]').attr('disabled', 'disabled'); 81 } 82 } 83 }); 84 85 /* 86 * Mixing in your own logic into the warning. 87 */ 88 $('#my-form').areYouSure( {'silent':true} ); 89 $(window).on('beforeunload', function() { 90 isSunday = (0 == (new Date()).getDay()); 91 if ($('#my-form').hasClass('dirty') && isSunday) { 92 return "Because it's Sunday, I'll be nice and let you know you forgot to save!"; 93 } 94 } 95 96}
The demo page shows the advanced usage options in more detail.
###Install Are-You-Sure is a light-weight jQuery plugin - it's a single standalone JavaScript file. You can download the jquery.are-you-sure.js file and include it in your page. Because it's so simple it seems a shame to add an extra browser round trip. It's recommended that you consider concatenating it with other common JS lib files, and/or even cut-n-pasting the code (and license header) into one of your existing JS files.
For experimental Mobile Safari support, also include ays-beforeunload-shim.js
(see Known Issues below).
Are-you-sure may also be installed with Bower:
1$ bower install jquery.are-you-sure
If you're using, or like, Are-you-sure make sure you star/watch this project so you can stay up-to-date with updates.
###Demo This demo page hosts a number of example forms.
###Supported Browsers Are-you-sure has been tested on and fully supports the following browsers:
Experimental support is available on iOS and Opera via the beforeunload shim (see below).
###Known Issues & Limitations
####Mobile Safari and Opera
The windows.beforeunload
event is not supported on iOS (iPhone, iPad, and iPod). An
experimental shim offering partial beforeunload emulation is provided to help plug this gap.
It works by scanning the page for anchor links and augments the default behaviour to first
check with Are-you-sure before navigating away. To use, simply include
ays-beforeunload-shim.js
in your page.
####Firefox The custom message option may not work on Firefox (Firefox bug 588292).
###Development The aim is to keep Are-you-sure simple and light. If you think you have a good idea which is aligned with this objective, please voice your thoughts in the issues list.
####Pull Requests
If possible, please submit your pull request against the most recent dev-*
branch rather than master. This will make it easier to merge your code into the next planned release.
####Running tests
1$ npm install 2$ npm test
###Release History
2014-08-13 (1.9) - This is a minor bugfix release:
2014-06-22 (1.8) - This is a minor bugfix release:
2014-05-28 (1.7)
2014-02-07 (1.6)
addRemoveFieldsMarksDirty
) (contrib jonegerton)2013-11-15 (1.5)
2013-10-2 (1.4)
2013-07-24 - Minor fix - don't fail if form elements have no "name" attribute.
2013-05-14 - Added support for form reset buttons (contributed by codev).
2013-05-01 - Added support for hidden and disabled form fields.
2013-02-03 - Add demo page.
2013-01-28 - Add change
event support and a demo page.
2012-10-26 - Use dashes in class names rather than camel case.
2012-10-24 - Initial public release.
###Prerequisites jQuery version 1.4.2 or higher. 2.0+ or 1.10+ recommended.
###License The same as JQuery...
jQuery Plugin: Are-You-Sure (Dirty Form Detection)
https://github.com/codedance/jquery.AreYouSure/
Copyright (c) 2012-2014, Chris Dance - PaperCut Software http://www.papercut.com/
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 7/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More