unload event more restrictive now on Safari 3.1 ?

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

    unload event more restrictive now on Safari 3.1 ?

    I've been using the unload event for a long time. I have this code,
    which I've abstracted and made into a stripped down simple test case
    below, and it works fine on the major browsers (IE5+, Firefox, Opera).
    It also works for all Safari versions before 3.1.

    It's as if they've deliberately made a change to prevent some actions in
    the unload handler. Has anyone heard of such a restriction?

    Here's the test case:

    <html><body>
    <a href="destinati on.html">click</a>
    <script>
    var started=new Date().getTime( );
    var imj;
    function fin()
    {
    var diff=(new Date().getTime( )-started)/1000;
    imj=new Image();
    imj.src="http://example.com/time.gif?"+diff ;
    // alert("fin");
    }
    if(window.addEv entListener)
    window.addEvent Listener('unloa d',fin,false);
    else if(window.attac hEvent)
    window.attachEv ent('onunload', fin);
    </script>
    <form><input type=button value="fin" onclick="fin()" ></form>
    </body></html>

    Each time you click the fin form button, you see (via a http monitor
    like Charles or Fiddler) that the image load occurs with the current
    time delta since page load as a cache-busting query string. The file
    gets a 404, but that doesn't matter, it's working fine when fin is
    called from the form button.

    If you instead click the link (or close the browser), fin is also called
    (confirmable by uncommenting the alert), but the image load doesn't occur.
  • Stevo

    #2
    Re: unload event more restrictive now on Safari 3.1 ?

    Stevo wrote:
    I've been using the unload event for a long time. I have this code,
    which I've abstracted and made into a stripped down simple test case
    below, and it works fine on the major browsers (IE5+, Firefox, Opera).
    It also works for all Safari versions before 3.1.
    >
    It's as if they've deliberately made a change to prevent some actions in
    the unload handler. Has anyone heard of such a restriction?
    Is nobody else affected by this?

    Comment

    • elivemedia@gmail.com

      #3
      Re: unload event more restrictive now on Safari 3.1 ?

      On Jun 16, 10:29 am, Stevo <n...@mail.inva lidwrote:
      I've been using the unload event for a long time. I have this code,
      which I've abstracted and made into a stripped down simple test case
      below, and it works fine on the major browsers (IE5+, Firefox, Opera).
      It also works for all Safari versions before 3.1.
      >
      It's as if they've deliberately made a change to prevent some actions in
      the unload handler. Has anyone heard of such a restriction?
      >
      Here's the test case:
      >
      <html><body>
      <a href="destinati on.html">click</a>
      <script>
      var started=new Date().getTime( );
      var imj;
      function fin()
      {
              var diff=(new Date().getTime( )-started)/1000;
              imj=new Image();
              imj.src="http://example.com/time.gif?"+diff ;
      //      alert("fin");}
      >
      if(window.addEv entListener)
              window.addEvent Listener('unloa d',fin,false);
      else if(window.attac hEvent)
              window.attachEv ent('onunload', fin);
      </script>
      <form><input type=button value="fin" onclick="fin()" ></form>
      </body></html>
      >
      Each time you click the fin form button, you see (via a http monitor
      like Charles or Fiddler) that the image load occurs with the current
      time delta since page load as a cache-busting query string. The file
      gets a 404, but that doesn't matter, it's working fine when fin is
      called from the form button.
      >
      If you instead click the link (or close the browser), fin is also called
      (confirmable by uncommenting the alert), but the image load doesn't occur.
      I am trying to do the same thing (load the image on window unload) and
      try everything imaginable to nothing works. It looks like it can't be
      done and this may be a question to someone familiar with architecture
      of Safari. It does work on all other major browsers though. If anybody
      has a fix for this please let us know. Thanks.

      Comment

      • Jorge

        #4
        Re: unload event more restrictive now on Safari 3.1 ?

        On Jun 16, 4:29 pm, Stevo <n...@mail.inva lidwrote:
        I've been using the unload event for a long time. I have this code,
        which I've abstracted and made into a stripped down simple test case
        below, and it works fine on the major browsers (IE5+, Firefox, Opera).
        It also works for all Safari versions before 3.1.
        >
        It's as if they've deliberately made a change to prevent some actions in
        the unload handler. Has anyone heard of such a restriction?
        >
        (...)
        >
        Each time you click the fin form button, you see (via a http monitor
        like Charles or Fiddler) that the image load occurs with the current
        time delta since page load as a cache-busting query string. The file
        gets a 404, but that doesn't matter, it's working fine when fin is
        called from the form button.
        >
        If you instead click the link (or close the browser), fin is also called
        (confirmable by uncommenting the alert), but the image load doesn't occur.
        Hi,

        When the window is closed, I think that by the time the handler gets
        called, Safari knows that the screen image of the current page is not
        going to be refreshed again, this may explain why the trigger to fetch
        the image never really happens.

        When surfing away to another page, inserting the image into the DOM
        migth be what forces it to load... or not.

        Here the image gets loaded : See : http://tinyurl.com/6lrv49

        You could instead use a synchronous XHR instead, S.O.P. permitting, to
        send your data. (If the image request is being made just to send some
        data back)
        Or, you could try to request a <scriptinstea d ? (it's S.O.P.-free,
        and has nothing to do with screen updates).

        HTH,
        --Jorge.

        Comment

        • elivemedia@gmail.com

          #5
          Re: unload event more restrictive now on Safari 3.1 ?

          On Jul 1, 7:05 pm, Jorge <jo...@jorgecha morro.comwrote:
          On Jun 16, 4:29 pm, Stevo <n...@mail.inva lidwrote:
          >
          >
          >
          I've been using the unload event for a long time. I have this code,
          which I've abstracted and made into a stripped down simple test case
          below, and it works fine on the major browsers (IE5+, Firefox, Opera).
          It also works for all Safari versions before 3.1.
          >
          It's as if they've deliberately made a change to prevent some actions in
          the unload handler. Has anyone heard of such a restriction?
          >
          (...)
          >
          Each time you click the fin form button, you see (via a http monitor
          like Charles or Fiddler) that the image load occurs with the current
          time delta since page load as a cache-busting query string. The file
          gets a 404, but that doesn't matter, it's working fine when fin is
          called from the form button.
          >
          If you instead click the link (or close the browser), fin is also called
          (confirmable by uncommenting the alert), but the image load doesn't occur.
          >
          Hi,
          >
          When the window is closed, I think that by the time the handler gets
          called, Safari knows that the screen image of the current page is not
          going to be refreshed again, this may explain why the trigger to fetch
          the image never really happens.
          >
          When surfing away to another page, inserting the image into the DOM
          migth be what forces it to load... or not.
          >
          Here the image gets loaded : See :http://tinyurl.com/6lrv49
          >
          You could instead use a synchronous XHR instead, S.O.P. permitting, to
          send your data. (If the image request is being made just to send some
          data back)
          Or, you could try to request a <scriptinstea d ? (it's S.O.P.-free,
          and has nothing to do with screen updates).
          >
          HTH,
          --Jorge.
          Hi Jorge,

          Unfortunatelly I can't use XMLHttpRequest is my script will be loaded
          on 3rd party sites and permissions to run it crosss site are denied
          (tried it before). The sad part is that Safari simly refuses to load
          the images on page unload. I am trying to load the images using
          img.src = ... and it works in all browsers but Safari. This will not
          allow me to track exit links in Safari so if anyone has suggestions
          how to overcome it I would really appreciate it. Thanks.

          Comment

          • Jorge

            #6
            Re: unload event more restrictive now on Safari 3.1 ?

            On Jul 2, 4:13 am, eliveme...@gmai l.com wrote:
            On Jul 1, 7:05 pm, Jorge <jo...@jorgecha morro.comwrote:
            >
            >
            >
            On Jun 16, 4:29 pm, Stevo <n...@mail.inva lidwrote:
            >
            I've been using the unload event for a long time. I have this code,
            which I've abstracted and made into a stripped down simple test case
            below, and it works fine on the major browsers (IE5+, Firefox, Opera)..
            It also works for all Safari versions before 3.1.
            >
            It's as if they've deliberately made a change to prevent some actionsin
            the unload handler. Has anyone heard of such a restriction?
            >
            (...)
            >
            Each time you click the fin form button, you see (via a http monitor
            like Charles or Fiddler) that the image load occurs with the current
            time delta since page load as a cache-busting query string. The file
            gets a 404, but that doesn't matter, it's working fine when fin is
            called from the form button.
            >
            If you instead click the link (or close the browser), fin is also called
            (confirmable by uncommenting the alert), but the image load doesn't occur.
            >
            Hi,
            >
            When the window is closed, I think that by the time the handler gets
            called, Safari knows that the screen image of the current page is not
            going to be refreshed again, this may explain why the trigger to fetch
            the image never really happens.
            >
            When surfing away to another page, inserting the image into the DOM
            migth be what forces it to load... or not.
            >
            Here the image gets loaded : See :http://tinyurl.com/6lrv49
            >
            You could instead use a synchronous XHR instead, S.O.P. permitting, to
            send your data. (If the image request is being made just to send some
            data back)
            Or, you could try to request a <scriptinstea d ? (it's S.O.P.-free,
            and has nothing to do with screen updates).
            >
            HTH,
            --Jorge.
            >
            Hi Jorge,
            >
            Unfortunatelly I can't use XMLHttpRequest is my script will be loaded
            on 3rd party sites and permissions to run it crosss site are denied
            (tried it before). The sad part is that Safari simly refuses to load
            the images on page unload. I am trying to load the images using
            img.src = ... and it works in all browsers but Safari. This will not
            allow me to track exit links in Safari so if anyone has suggestions
            how to overcome it I would really appreciate it. Thanks.
            Have you tried it with something like this

            script= document.create Element("script ");
            script.type ='text/javascript';
            script.charset ='utf-8';
            script.src= "whatever?"+you rData;
            (document.getEl ementsByTagName ('head')[0]).appendChild(s cript);

            instead of the <img?

            --Jorge.

            Comment

            • elivemedia@gmail.com

              #7
              Re: unload event more restrictive now on Safari 3.1 ?

              On Jul 1, 10:43 pm, Jorge <jo...@jorgecha morro.comwrote:
              On Jul 2, 4:13 am, eliveme...@gmai l.com wrote:
              >
              >
              >
              >
              >
              On Jul 1, 7:05 pm, Jorge <jo...@jorgecha morro.comwrote:
              >
              On Jun 16, 4:29 pm, Stevo <n...@mail.inva lidwrote:
              >
              I've been using the unload event for a long time. I have this code,
              which I've abstracted and made into a stripped down simple test case
              below, and it works fine on the major browsers (IE5+, Firefox, Opera).
              It also works for all Safari versions before 3.1.
              >
              It's as if they've deliberately made a change to prevent some actions in
              the unload handler. Has anyone heard of such a restriction?
              >
              (...)
              >
              Each time you click the fin form button, you see (via a http monitor
              like Charles or Fiddler) that the image load occurs with the current
              time delta since page load as a cache-busting query string. The file
              gets a 404, but that doesn't matter, it's working fine when fin is
              called from the form button.
              >
              If you instead click the link (or close the browser), fin is also called
              (confirmable by uncommenting the alert), but the image load doesn'toccur.
              >
              Hi,
              >
              When the window is closed, I think that by the time the handler gets
              called, Safari knows that the screen image of the current page is not
              going to be refreshed again, this may explain why the trigger to fetch
              the image never really happens.
              >
              When surfing away to another page, inserting the image into the DOM
              migth be what forces it to load... or not.
              >
              Here the image gets loaded : See :http://tinyurl.com/6lrv49
              >
              You could instead use a synchronous XHR instead, S.O.P. permitting, to
              send your data. (If the image request is being made just to send some
              data back)
              Or, you could try to request a <scriptinstea d ? (it's S.O.P.-free,
              and has nothing to do with screen updates).
              >
              HTH,
              --Jorge.
              >
              Hi Jorge,
              >
              Unfortunatelly I can't use XMLHttpRequest is my script will be loaded
              on 3rd party sites and permissions to run it crosss site are denied
              (tried it before). The sad part is that Safari simly refuses to load
              the images on page unload. I am trying to load the images using
              img.src = ... and it works in all browsers but Safari. This will not
              allow me to track exit links in Safari so if anyone has suggestions
              how to overcome it I would really appreciate it. Thanks.
              >
              Have you tried it with something like this
              >
                  script= document.create Element("script ");
                  script.type ='text/javascript';
                  script.charset ='utf-8';
                  script.src= "whatever?"+you rData;
                  (document.getEl ementsByTagName ('head')[0]).appendChild(s cript);
              >
              instead of the <img?
              >
              --Jorge.- Hide quoted text -
              >
              - Show quoted text -
              Hi Jorge,

              I've tried the script approach you have suggested. Unfortunatelly it
              did not work on Safari again. It did work for all other browsers (IE,
              Firefox, Opera). As beofre, I suspect that Safari does not load or ads
              element to the document while the document is unloading. The code is
              executing without an error but the object doesn't load. I think this
              question can only be answered by someone on Safari's technical team.:(
              Not sure what else I can try at this point. Thanks anyways.

              Comment

              • Jorge

                #8
                Re: unload event more restrictive now on Safari 3.1 ?

                On Jul 6, 10:04 pm, eliveme...@gmai l.com wrote:
                Hi Jorge,
                >
                I've tried the script approach you have suggested. Unfortunatelly it
                did not work on Safari again. It did work for all other browsers (IE,
                Firefox, Opera). As beofre, I suspect that Safari does not load or ads
                element to the document while the document is unloading. The code is
                executing without an error but the object doesn't load. I think this
                question can only be answered by someone on Safari's technical team.:(
                Not sure what else I can try at this point. Thanks anyways.
                I've entered it as a bug report @ https://bugs.webkit.org/ (# 19922).

                HTH,
                --Jorge.

                Comment

                • Stevo

                  #9
                  Re: unload event more restrictive now on Safari 3.1 ?

                  Jorge wrote:
                  On Jul 6, 10:04 pm, eliveme...@gmai l.com wrote:
                  I've entered it as a bug report @ https://bugs.webkit.org/ (# 19922).
                  --Jorge.
                  Thanks for logging that Jorge. The direct link for anyone that wants to
                  add their comments to the bug:



                  If they think it's only Jorge and me that have noticed it, they might
                  not be motivated enough to fix it. If it bothers you too, let them know.

                  Comment

                  • elivemedia@gmail.com

                    #10
                    Re: unload event more restrictive now on Safari 3.1 ?

                    On Jul 7, 5:01 am, Stevo <n...@mail.inva lidwrote:
                    Jorge wrote:
                    On Jul 6, 10:04 pm, eliveme...@gmai l.com wrote:
                    I've entered it as a bug report @https://bugs.webkit.org/(# 19922).
                    --Jorge.
                    >
                    Thanks for logging that Jorge. The direct link for anyone that wants to
                    add their comments to the bug:
                    >

                    >
                    If they think it's only Jorge and me that have noticed it, they might
                    not be motivated enough to fix it. If it bothers you too, let them know.
                    I want to mentioned that workaround proposed by Jorge is working only
                    in those cases when the script is loading on the same server where the
                    calling page resides. In my case, I am creating a tracking service
                    and new XMLHttpRequest( ) is not allowed to execute since this bit of
                    code is loading from another site (tracking service). Hopefully the
                    original bug will be resolved and I will be able to use img.src
                    assignment to load the tracking string. Thanks for all your help Jorge
                    and Stevo.

                    Comment

                    • elivemedia@gmail.com

                      #11
                      Re: unload event more restrictive now on Safari 3.1 ?

                      On Jul 7, 5:01 am, Stevo <n...@mail.inva lidwrote:
                      Jorge wrote:
                      On Jul 6, 10:04 pm, eliveme...@gmai l.com wrote:
                      I've entered it as a bug report @https://bugs.webkit.org/(# 19922).
                      --Jorge.
                      >
                      Thanks for logging that Jorge. The direct link for anyone that wants to
                      add their comments to the bug:
                      >

                      >
                      If they think it's only Jorge and me that have noticed it, they might
                      not be motivated enough to fix it. If it bothers you too, let them know.
                      Stevo,

                      Any luck getting through to webkit team? I get a feeling that this
                      will not be high on their priority list.
                      Thanks.

                      Comment

                      • Stevo

                        #12
                        Re: unload event more restrictive now on Safari 3.1 ?

                        elivemedia@gmai l.com wrote:
                        On Jul 7, 5:01 am, Stevo <n...@mail.inva lidwrote:
                        >Jorge wrote:
                        >>On Jul 6, 10:04 pm, eliveme...@gmai l.com wrote:
                        >>I've entered it as a bug report @https://bugs.webkit.org/(# 19922).
                        >>--Jorge.
                        >Thanks for logging that Jorge. The direct link for anyone that wants to
                        >add their comments to the bug:
                        >>
                        >https://bugs.webkit.org/show_bug.cgi?id=19922
                        >>
                        >If they think it's only Jorge and me that have noticed it, they might
                        >not be motivated enough to fix it. If it bothers you too, let them know.
                        >
                        Stevo,
                        >
                        Any luck getting through to webkit team? I get a feeling that this
                        will not be high on their priority list.
                        Thanks.
                        I've given up on that avenue of investigation. They don't seem to be
                        looking at any bugs below the priority of critical or blocker. I doubt
                        this will be dealt with before 3.2 is released, unless Jorge notices my
                        requests to increase the priority.

                        Until it gets resolved, we're having to offer a degraded service to
                        Safari 3.1 users.

                        Comment

                        Working...