Return to view after document is closed

View member feedback to this tip.

If you have multiple views that link to the same documents, it can be convenient to return a user to the view they used to open a document when the document is submitted or closed.

One way to do this is to set the view name in the cookie whenever you leave the view, then use the cookie to reopen the last view by invoking some JavaScript to go to the last view.

In the onunload event of the $$ViewTemplate form, add the following code:

document.cookie = "lastView=" + 
escape (document.location)+";path=/";

Add the following functions to a script library or JSHeader:

function bk() {
 var lastView =GetCookie("lastView");
 if (lastView) {top.document.location=
lastView; return}
 history.go(-2);
}

function getCookieVal (offset) {
 var endstr = document.cookie.indexOf (";", offset);
 if (endstr == -1) { endstr = 
document.cookie.length; }
 return unescape(document.
cookie.substring(offset, endstr));
 }
 
function GetCookie (name) {
 var arg = name + "=";
 var alen = arg.length;
 var clen = document.cookie.length;
 var i = 0;
 while (i < clen) {
  var j = i + alen;
  if (document.cookie.substring(i, j) == arg) {
   return getCookieVal (j);
   }
  i = document.cookie.indexOf(" ", i) + 1;
  if (i == 0) break; 
  }
 return null;
 }

In the $$Return field, a cancel button, or another action, calls the "bk()" function. For example, you could put the following in the $$Return field: <script>bk();</script>

MEMBER FEEDBACK TO THIS TIP

I prefer a different technique that doesn't require a cookie. When creating the link to open the document, add a URL parameter containing the name of the $$ViewTemplate alias. For example:

&form=. You can do this in a view column definition of the embedded view.

When creating the $$Return for the newly opened document use @UrlQueryString("form") to code the return link to open the calling form -- no cookie needed. For example:

$$Return (set FormName to the URL 
Parameter value &form=) 
"<SCRIPT language=\"JavaScript\
">javascript:window.location=\"http://" + 
Server_Name + "/" + dbName + "/" + FormName +
 "?OpenForm"+ "\"</SCRIPT>"

—Douglas F.

Do you have comments on this tip? Let us know.

This tip was submitted to the SearchDomino.com tip exchange by member Chad Cole. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our monthly tip contest and you could win a prize and a spot in our Hall of Fame.

This was first published in February 2005

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.