Safari 3 and refresh

A

Andrew Poulos

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
 
P

pr

Andrew said:
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]-->
[...]


Is there anything that can be done to get Safari to behave?

Not wanting to stir up that whole JavaScript Ninja thing again :)
nevertheless you might find this useful: <URL:
http://ejohn.org/blog/keypress-in-safari-31/>.
 
V

VK

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.

What about right-click - context menu - Refresh or direct address bar
typing? (the address bar cannot be removed for IE7/8 for security
consideration).

I would highly suggest to use onbeforeunload instead that covers all
navigation away situations.

For Safari and Opera where "onbeforeunload" property is spoofed but
not implemented: it is just too bad for the leftovers of their
remaining users. Eventually they will migrate on some more usable
platforms - it takes just 2-3 big almost filled forms lost on
different sites as the practice shows. Some may have a different
opinion.

// IE + Firefox:

window.onbeforeunload = warnNavigateAway;

function warnNavigateAway() {
var message = ''.concat(
'You are attempting to navigate away ',
'from the current page.\n',
'If you leave now then ',
'all current data will be lost.');

if ((typeof event == 'object') && ('returnValue' in event)) {
event.returnValue = message;
}
else {
return message;
}
}
 
T

Thomas 'PointedEars' Lahn

VK said:
// + Camino of course for MacOS users

There is also a Firefox version for Mac OS X. It would be easier (and
correct) to say Mozilla/5.0 (the codebase) or Gecko (the layout engine),
because there are much more browsers based on either than just Firefox and
Camino.


PointedEars
 
V

VK

// + Camino of course for MacOS users
There is also a Firefox version for Mac OS X. It would be easier (and
correct) to say Mozilla/5.0 (the codebase) or Gecko (the layout engine),
because there are much more browsers based on either than just Firefox and
Camino.

Mozilla Foundation is an open source project. Anyone can take the
source http://developer.mozilla.org/en/docs/Download_Mozilla_Source_Code
and to build yet another browser without any care of Mozilla feature
guidelines - as long as it uses the "generic globe" instead of "foxy
globe" logo and some other little copyright details. The process can
be rather easily automated with a randomizer added over some batch
script so one could produce up to 40 slightly different browsers per
hour depending on the CPU speed. :)
This way it is pointless to name all Gecko-based browsers. I named
Camino because I know the project and because it is a reputable long-
existing brand I can suggest for MacOS. It is also the only one
natively running 3rd party browser plus with AppleScript support.
 
T

Thomas 'PointedEars' Lahn

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top