473,695 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jun 27 '08 #1
11 2438
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?
Jun 27 '08 #2
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.
Jul 1 '08 #3
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.
Jul 1 '08 #4
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.
Jul 2 '08 #5
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.
Jul 2 '08 #6
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.

Jul 6 '08 #7
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.
Jul 7 '08 #8
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.
Jul 7 '08 #9
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.
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.
Jul 8 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
20848
by: Harry J. Smith | last post by:
I have written a Visual Basic program that does a long calculation and writes the results to disk as it runs. If I click the Close button the window closes but the program keeps running. How can I get the program to recognize that its window has been closed and quit running? -Harry http://home.netcom.com/~hjsmith
2
2028
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function keysuppress(e) { if (e.type=="keypress" && e.keyCode=="13") { event.returnValue=false
1
4601
by: David A. Beck | last post by:
I have a frameset with an index frame and a main frame. The aspx pages in the main frame are loaded based on the hyperlinks clicked in the index frame. In any aspx page in the main frame I want to save the information in the various controls before the new aspx page is loaded. I thought I could use the Page event Unload, but it does not seem to be triggering when the aspx page is replaced in the frame by another aspx page.
1
2651
by: hal | last post by:
I have an application that includes an activex component that consumes resources that must be released when the a page is unloaded. Toward this end I subscribe to the unload event of the body of my page in javascript. However, if I turn on smart navigation, any button that does a server.transfer fails to fire the javascript unload event.
1
2926
by: Hal | last post by:
My most sincere gratitude to anyone who can help me work around this! I have work that needs to be done in javascript on the client whenever a page is unloaded. To this end, I subscribe to the unload event (client side not server side) of the <body> HTML element through javascript.
6
18419
by: Mike | last post by:
I have a web form in my application that will be used for both viewing and updating information. I have a requirement that if any data has been changed on the page and the user attempts to leave the page without saving, the user gets prompted with a message asking if they want to save changes. It seemed logical to put any code to handle this in the page unload event, however the page unload event gets fired every time the page does a post...
3
3209
by: Gauthier Segay | last post by:
Hello, I've an application where all my pages implement a PAGE_CODE string property, this property is stored in HttpContext.Current.Items. In some page, I must persist data in session while the user perform operation on this page (postback navigation based). I also need to clean up the session data when the user leave the page (by a anyway). My question is about the Unload event, is it safe to use the unload
2
8165
by: Owen.Leibman | last post by:
Here is a complete web page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>Javascript Embed and onunload</title> <script type="text/javascript"> function useplayer() { var a = document.getElementById("obj1"); var obj = document.createElement("object"); obj.data = "dayenu.mid";
5
5897
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
It seems that one page XBAP whose Unloaded event never get called, I need put some clearing stuff (I.G stop dispatcher time) when user close browser, it unload event doesn't work, where shall I put? -- ======================= Steven Tang SYWWUYU)
0
8647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9129
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7681
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2285
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.