Thursday, January 18, 2007

Domino forms and the Back button of the browser

Suppose you have a sequence of application steps as following:
UNID?EditDocument -> user change -> document is saved and redirect user to UNID?OpenDocument

More than that, suppose it's an application already working, which performs a JS sumbit(), then the WQS agent kicks in, create the document, then the same agent does :
Print "[/" & web_db_name & "/(someView)/" & docSaved.UniversalID & "?OpenDocument]"
which is basically the redirection.

Where does the Back button fit this picture ? from OpenDocument resulting page, if the user performs Right Click/Back, it ends up in the same EditDocument page and you don't want that. What to do ?

The simplest solution to avoid this:
Instead of printing the redirection URL directly, print the HTML code of a page which performs the redirection on the onload event. The code would look like this:


Sub Initialize

... set doc context, perform some rocket science

Dim sLocation As String

sLocation= "/" + UtilEscapePath (db.FilePath) + "/(someView)/" & docSaved.UniversalID & "!OpenDocument"

WebReturnUrl (sLocation)

End Sub


The UtilEscapePath and WebReturnUrl are two subroutines which you can find in the names.nsf of your server (WebLSUtil library, for Domino 6). Thanks IBM for that, good idea ! It is sometimes useful to have a look into the design of Domino default templates, specific the system names.nsf :)
UtilEscapePath basically changes \ with / so it will comply with URL format. Most interesting is WebReturnUrl:


Sub WebReturnUrl(sLocation As String)

Print _

|content-type:text/html

<html>

<body onLoad="window.location = '| + sLocation & |'"></body>

</html>

|

End Sub


There you have it, the first 'level' of Back will no longer open the document in Edit mode. This is not a full-proof solution as selecting browser's drop-down and going back two 'levels' will of course break this. However for the 'right-click/back' it works and may be sufficient for your application.

1 comment:

Anonymous said...

Thanks, I have used this and it solved my problem. Keep up the good work Radu.

Best Regards,

Remi