Call action with javascript onunload event

Call action with javascript onunload event


I´m trying to call a action to save some data in a record, just before the user leaves the page, using the javascript onunload event, but i can't make it work, using the alert function in javascript i can tell with works, but i can call a action.

Any ideias ?

Thanks in advanced.
Hi Nuno,

I guess you could create a button (e.g. MyButton) that calls the action you want with an extended property style set to "display:none" and the on a screen extended property onunload put "myunloadfunction('" + MyButton.Id + "')"
function myunloadfunction(buttonId)}


Tiago Simões
Or maybe make an asynchronous Ajax request, to a screen with the action as the screen preparation, so as not to lock the user while the action is being executed.
I use this...

<div id="ScreenExit" style="display:none;"></div>
<script type="text/javascript">
// URLget(thisURL, thisNodeId)
// Execute the thisURL page. Page output stored in the thisNodeId div.
// Needs: <div id="thisNodeId" style="display:none;"></div> in body of page.
// I tried it without rfNodeId.innerHTML = xmlhttp.responseText; or the div but got uneven results.
function URLget(thisURL, thisNodeId) {
if (thisURL != undefined && thisNodeId != undefined && thisURL != '' && thisNodeId != '') {
//alert("URLget "+thisURL+" "+thisNodeId);
if (arguments.length!=0) {
xmlhttp=getHTTPObject();//new XMLHttpRequest();"GET", thisURL);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
rfNodeId.innerHTML = xmlhttp.responseText;

// ExitScreen()
// Calls URLget to call my page onunload.
function ExitScreen() {

Replace /full/path/to/yourPage.php with your page.
I apologise for the formating, but I don't know how to indent in this forum (tabs are stripped)