Ok, this works in a button:
if (XSP._isDirty()){
if (confirm ("Are you sure you want to navigate away from this page?")){
XSP._setDirty(false,"");
return true
}else{
return false;
}
I still need a good solution for closing the tab or the browser. enableModifiedFlag will prompt the user, but it will not use the message I enter!