Safari 3 and refresh

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Poulos

    Safari 3 and refresh

    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">sTy pe = "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.preventDefau lt) {
    e.stopPropagati on();
    e.preventDefaul t();
    } else {
    e.keyCode = 0;
    e.returnValue = false;
    e.cancelBubble = true;
    }
    return false;
    };

    fAddEvent = function(obj, type, fn) {
    if (obj.addEventLi stener) {
    obj.addEventLis tener(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(docum ent, sType,fIntercep t);

    </script>


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

    Andrew Poulos
  • pr

    #2
    Re: Safari 3 and refresh

    Andrew Poulos wrote:
    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">sTy pe = "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/>.

    Comment

    • VK

      #3
      Re: Safari 3 and refresh

      On Apr 22, 10:44 am, Andrew Poulos <ap_p...@hotmai l.comwrote:
      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.onbefore unload = warnNavigateAwa y;

      function warnNavigateAwa y() {
      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.returnVal ue = message;
      }
      else {
      return message;
      }
      }

      Comment

      • VK

        #4
        Re: Safari 3 and refresh

        On Apr 22, 4:49 pm, VK <schools_r...@y ahoo.comwrote:
        // IE + Firefox:
        // + Camino of course for MacOS users
        window.onbefore unload = warnNavigateAwa y;
        >
        function warnNavigateAwa y() {
        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.returnVal ue = message;
        }
        else {
        return message;
        }
        >
        }

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Safari 3 and refresh

          VK wrote:
          On Apr 22, 4:49 pm, VK <schools_r...@y ahoo.comwrote:
          >// IE + Firefox:
          >
          // + 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
          --
          Use any version of Microsoft Frontpage to create your site.
          (This won't prevent people from viewing your source, but no one
          will want to steal it.)
          -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

          Comment

          • VK

            #6
            Re: Safari 3 and refresh

            // + 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...la_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.

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Safari 3 and refresh

              VK wrote:
              >>// + 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.
              No, Mozilla Foundation is a non-profit organization that maintains an open
              source project called Mozilla(/5.0).
              Anyone can take the source
              http://developer.mozilla.org/en/docs...la_Source_Code and to
              build yet another browser [...] This way it is pointless to name all
              Gecko-based browsers. [...]
              That is exactly what I pointed out to you.


              PointedEars
              --
              Use any version of Microsoft Frontpage to create your site.
              (This won't prevent people from viewing your source, but no one
              will want to steal it.)
              -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

              Comment

              Working...