If you try to send an Ajax request, a JSONP request, or even a window.name request on unload, Safari and Chrome run the code, but the server never sees the request. My theory is the thread of execution never allows the script tag to run before it changes the page. Here is a test page with the JSONP test. This code (and Ajax and window.name) creates a request for test.html in Firefox and IE7, but not Safari:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<script language="javascript" type="text/javascript">
window.onunload = function(){
var encode = "UTF-8";
var script = document.createElement('script');
script.type = 'text/javascript';
script.src= "/test.html";
script.charset= encode;
document.body.appendChild(script)
}
</script>
</body>
</html>
Anyone know a good way to get around this? More specifically, anyone know of a way to force Safari to send a request on unload? The only solution I've found (which doesn't really help in my case) is synchronous XHR.