First of all, I am not trying to use the browsers forward and backwards button. What I am trying to do is add a forward and backward button to a dialog.

The dialog will have some links which contain the page ID instead of a real href, and if clicked will use ajax to return the content for that given page with potentially more links.

I am struggling on how to keep track of the history. I suppose that every time I click a link, I must push the id to an array. If I go backwards, I can't remove the page ID because it will still be needed for the forward button. But if going back, and then forward up a different tree, I need to delete the page IDs up the no longer current tree.

I hope I am making at least some sense, and believe I am not the first person to try to do this. Any recommendations on how to accomplish it?

Thank you