Well, I am not sure what you are exactly doing to save the data. But to make the event beforeunload to work for other browsers, have a look at this
link[
^]. Though, it talks for FF, but works same for others browsers as well.
Though, it is off topic but lately I have been loving
jQuery [
^]for its capability to handle these cross broswer implementation. With jQuery you can do something like this.
$(document).ready(function ()
{
jQuery(window).bind('beforeunload', function ()
{
SaveData();
});
});
EDIT: adding more explanation to OPs question to where to write this code?
add this code in the head section. also look at
https://developer.mozilla.org/en/DOM/window.onbeforeunload
<head>
<script>
window.onbeforeunload = function (e)
{
var e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Any string';
}
// For Safari
return 'Any string';
};
</script>
</head>