Creating a back button

I want to add a button to my web pages to take the user back to the page they came from. I have tried to implement a form of tracking which page was the previous page but it doesnt work (my bad coding) and I was wondering if Xojo had any built in facility to access the page stack or some other clever way.

Why not simply use HTML code for this?

<FORM><INPUT Type="button" VALUE="Back" onClick="history.go(-1);return true;"></FORM>

Source: http://www.computerhope.com/issues/ch000317.htm

I dont think that works because Xojo WE only has one actual page and everything else is loaded dynamically into that page.

This is why you need to have some type of internal history to be able to do a “zzz.show” to reshow the page (using implicit instance).

Their must be a way of cycling though the session page history and storing the name into a webpage object and then doing a show using that object.

Keep the page index in an array and step back and forth in it and use Session.PageAtIndex ?

How would you then show that page then?

Session.PageAtIndex(index).Show
I have not tried this though.
Theres also PageWithName and PageWithID that I “think” you might be able to use :slight_smile:

That sounds like exactly what I was after, thanks.

Well, why not keep an array in the session of pages visited?
When you go to new page, put it on the stack and when you want to go back, pick the top one.

Ok but I am struggling with what type of array, can you have an array of type webpage? So could I then do something like:

myWebpages(myWebpages.Ubound - 1).show

Yes. Dim mypages(n) as webpage

you can have array of webpage.

Add:
session.webpages.append webpage1

and go back
dim pages() as webpage = session.webpages
if pages.ubound >= 0 then
dim p as webpage = pages.pop
p.show
else
// ?
end if

I have a generic report module I wrote in Web Edition which can be called from any Window from any app. I pass the report WebPage the current WebPage to a Property, so if they click the Back button it looks to see if that BackPage <> nil and if so, it shows it.

What does “.pop” do?

A pop returns the last element of the array and then removes it.

I never knew you could do that, I have always done it manually.

Remember that a good Back button will have a companion Forward button, so you should keep a forward stack as well, of pages which have been popped, so you can go forward to them. The usual way to do things is to then clear that array when the user clicks on anything other than the Forward button.

Thanks for the suggestion but for what I am doing it is simply to take a user from a details page back to the page that has a listbox on it. The thing is that I have a number of pages that use said details page and this will increase so I wanted an easy way to have a generic back button the details page to take the user back to the page that they came from with the listbox on.

OK, no problem. Given that the back/forward paradigm is well understood by people, I’d suggest naming it something other than plain ‘back’ - i.e. ‘back to the list’, or a button with a little icon of a list, or something like that.
H

Yes thats a good idea, have changed it to “Back to List”

[quote=96333:@Christian Schmitz]you can have array of webpage.

Add:
session.webpages.append webpage1

and go back
dim pages() as webpage = session.webpages
if pages.ubound >= 0 then
dim p as webpage = pages.pop
p.show
else
// ?
end if[/quote]
Any idea the reason I am ending up with a blank page with the name of the project at the top left corner?