CRM 2011: Are you sure you want to leave this page?

in CRM 2011, when closing by calling the Xrm.Page.ui.close() method, if one of the fields on the form is dirty for some reason (and some reasons can be strange), then you will get the following message:

Are you sure you want to leave this page? Message from webpage: Your changes have not been saved. To stay on the page so that you can save your changes, click Cancel.

Using the code below, you can get rid of this sometimes annoying message:

var attributes = Xrm.Page.data.entity.attributes.get();
for (var i in attributes)
{
if (attributes[i].getIsDirty())  {
attributes[i].setSubmitMode(“never”);
}
}