Subject: Unlock Documents if browser is closed with “X” (Close Button of Browser)
Rodrigo,
Maybe using AJAX in combination with onbeforeunload you can determine whether the window was canceled by clicking on the “X” or by clicking on the Cancel button. The code in your Cancel button can be modified to set the value of a flag field (for example NeedsUnlock) which is checked by the code to see if the agent to unlock the document should be run.
I have tried the approach below on local server (I don’t have access to a Domino server as I was compsong this response) and it does appear to trigger the agent (agent log shows the agent was run).
Set it up by adding the following to the HTML Body Attributes:
“onbeforeunload="RunAgent()"”
Then, in the JS Header, add the following code:
var http_request = false;
function RunAgent() {
if(window.document.forms[0].NeedsUnlock.value == true) {
var dbUrl = new String(location.href.slice(0, location.href.indexOf(‘.nsf’)+4));
var agentURL = dbUrl + ‘/UnlockDoc?OpenAgent’;
makeRequest(agentURL, ‘&docUNID=’ + window.documents.forms[0].UniversalID.value);
}
}
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
alert('Non-MSIE');
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
alert('MSIE');
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
//http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
Credit to:
Espero que tudo isso faz sentido. Se nao, pode escrever direto para meu e-mail: cesinco@yahoo.ca