Skip to Content (Press Enter)
OutSystems.com
Personal Edition
Community
Support
Training
Training
Online Training
Developer Schools
Boot Camps
Certifications
Tech Talks
Documentation
Documentation
Overview
ODC
O11
Forums
Forge
Get Involved
Get Involved
Jobs
Ideas
Members
Mentorship
User Groups
Platform
Platform
ODC
O11
Search in OutSystems
Log in
Get Started
Back to Forums
Nuno Bispo
360
Views
3
Comments
Call action with javascript onunload event
Question
Hello.
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.
Tiago Simões
Staff
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)}
document.getElementByyId(buttonId).click();
}
Cheers,
Tiago Simões
André Ramos
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.
Jim Martinson
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();
xmlhttp.open("GET", thisURL);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
rfNodeId.innerHTML = xmlhttp.responseText;
//alert(xmlhttp.responseText);
}
}
xmlhttp.send(null);
}
}
}
// ExitScreen()
// Calls URLget to call my page onunload.
function ExitScreen() {
URLget('/full/path/to/yourPage.php','ScreenExit');
}
window.onload=ExitScreen;
</script>
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)
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
See the full guidelines
Loading...