I'm building a app in which opens in a new window without a menu bar or
tool bar. I need to warn users (who press the F5 key or Ctrl+R) that
refreshing may result in loss of data and to give them the option of
cancelling the refresh.
The code is relatively straightforward and works for IE, FF and Opera
but the intercept code is ignored by Safari 3.1 for Windows.
Following is part of the code that I'm using.
<script type="text/javascript">var sType = "keypress";</script>
<!--[if IE]>
<script type="text/javascript">sType = "keydown";</script>
<![endif]-->
<script type="text/javascript">
fIntercept = function(e) {
e = e || event.e;
if (e.keyCode == 116) {
// When F5 is pressed
fCancel(e);
} else if (e.ctrlKey && e.keyCode == 82) {
// When ctrl is pressed with R
fCancel(e);
}
};
fCancel = function(e) {
if (e.preventDefault) {
e.stopPropagation();
e.preventDefault();
} else {
e.keyCode = 0;
e.returnValue = false;
e.cancelBubble = true;
}
return false;
};
fAddEvent = function(obj, type, fn) {
if (obj.addEventListener) {
obj.addEventListener(type, fn, false);
} else {
obj['e'+type+fn] = fn;
obj[type+fn] = function() {
obj['e'+type+fn](window.event);
}
obj.attachEvent('on'+type, obj[type+fn]);
}
};
fAddEvent(document, sType,fIntercept);
</script>
Is there anything that can be done to get Safari to behave?
Andrew Poulos