Performe a action when page closes

Performe a action when page closes

  
Is there a way to perform an action when a page is unloaded (when the browser back button is pushed or page is closed)?
Hello Matthias,

What about triggering an HTTP request using JavaScript when the window.onunload (or in some browsers window onbeforeunload) event happens?

That HTTP request should call a screen where your action should be placed in the preparation.

The above events are triggered not only when the browser closes... be careful.

Hope it helps.
Regards,
Pedro
Thank you Pedro,

I did the following and this is working fine in FireFox but it doesn't work in Internet Explorer.

I added a Expression with the following escaped content:

<SCRIPT TYPE=""text/javascript"">
<!--
window.onbeforeunload = function() {
// Create a new XMLHttpRequest object
var AJAX=new XMLHttpRequest();

// Handle ready state changes ( ignore them until readyState = 4 )
AJAX.onreadystatechange= function() { if (AJAX.readyState!=4) return false; }
// And Execute the Unlock
AJAX.open(""GET"", """+UnlockURL+""", false);
AJAX.send(null);
window.onunload = null; } -->
</SCRIPT>
Found it, IE5 and IE6 uses ActiveXObject instead of native XMLHttpRequest

code sample:
"
<SCRIPT TYPE=""text/javascript"">
<!--
window.onbeforeunload = function() {
// Create a new XMLHttpRequest object
if (window.XMLHttpRequest){
// If IE7, Mozilla, Safari, etc: Use native object
var AJAX=new XMLHttpRequest()
}
else
{
if (window.ActiveXObject){

// ...otherwise, use the ActiveX control for IE5.x and IE6
var AJAX=new ActiveXObject(""Microsoft.XMLHTTP"");
}
}

// Handle ready state changes ( ignore them until readyState = 4 )
AJAX.onreadystatechange= function() { if (AJAX.readyState!=4) return false; }
// And Execute the Unlock
AJAX.open(""GET"", """+UnlockURL+""", false);
AJAX.send(null); } --> </SCRIPT>
"