I have a simple Xpage (page1.xsp) opened from view.xsp page. It contains the following elements
1) Back button written in SSJS
context.redirectToPreviousPage()
2) CSJS script that does ajax get every x minutes
dojo.xhr.get({
url:"page2.xsp?param1=value1",
handleAs:"text"
});
My probem is that after several ajax requests my Back button goes to page2.xsp (ajax get page) instead of view.xsp.
How can I make it go back to view.xsp page?
The back button and XHR behave very different in different browsers, so I wouldn't rely on it. Relying on a session variable is - as you pointed out - could become messy. So this is what I would do: store the page to return to in a session variable (yes), but only to hand it over to the page the very moment.
Pack it into a script tag using var whereToGoBackTo = '${sessionScope.theLastPageCameFrom}'
and store it client side. Since it is only evaluated on first page load, it doesn't matter if it gets changed by other tabs later. Then use CSJS to navigate back.
You could consider an URL parameter, but I'd rather keep my URL clean