Unlock Documents if browser is closed with "X" (Close Button of Browser)

Good Morning!

I have something applications in Domino 7 web using lock.

When user choice edit the document, the form run a agent in WebQueryOpen when @IsDocBeingEdited & !@IsNewDoc and lock the document.

When user save the document, the form run a agent for unlock document.

Ok, this solutions is work, but if user close a window using “X”(Close Button of browse) I can’t Unlock a document.

I try, call agent for unlock on the “unload” javascript function, but a popup is open and close. The user not like this solution.

Exist any solution for unlock documents if browser is “force” closed?

Somebody help me?

(Im a brazilian and my english is not the best, but I understand prefectly, sorry, tks)

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

Subject: RE: Unlock Documents if browser is closed with “X” (Close Button of Browser)

OMG man!

Very Very Very thanks!!!

Is prefect code! =)

Thank you so much!

See you.