harvesthq/chosen — Issue #452: Chosen causes window.onbeforeunload to execute in IE9
Author: keithslater
Created: 2012-01-19 15:19:04+00:00
State: open

I have tested this in Chrome and IE9 and I only have this problem with IE9. I have a script that checks to see if a user has changed input boxes and if they have, it will alert them if they try to leave the page without saving. In IE9, every time they click a chosen dropdown, it goes off. Here is the code I am using:

```javascript
function setConfirmUnload(on) {
var message = "You have unsaved data.";
window.onbeforeunload = (on) ? function() { return message; } : null;
}

$(':input').on('change', function() {
setConfirmUnload(true);
});

$('#cancel_button').on('click', function() {
setConfirmUnload(false);
});

$('form').on('submit', function() {
setConfirmUnload(false);
});
```