Session.HashtagChanged doesn't always fire

Hey all,

In my development of our web app we are using the Session.HashtagChanged event to change the page on back and forward in the browser, which usually works pretty well. Recently though, sometimes when you use the either the back or forward the hashtag in the browser changes, but the page does not. If you go back again the hashtag changes again and it switches to that page. Has anybody else seen this or found a fix? This seems like I’m missing something that is stopping the event from seeing the change.

Thanks,
CJ

I’ve noticed this. However, I can’t seem to replicate it. It just happens seemingly…random(?). Where do you set the hashtag for the window?

I’ve been Tim Parnell’s suggestion.

I am using the same thing from Tim, and it has worked well. I’m getting the same thing you are it sounds like. I’m using the setHashtag in the shown event for each page.

If you’re trying to record the current state/page, I suggest you try Session.SaveState instead.

https://documentation.xojo.com/api/web/websession.html#websession-savestate

I don’t believe that’s what we’re trying to do, but maybe I’m misunderstanding it. The only thing I’m trying to do is let the user navigate back and forth between pages using that back button in the browser. To do this I’m using the HashTagChanged event to switch the page. I’m using Tim Parnell’s method to change the hashtag in the browser so that you can’t accidentally hit a never-ending loop of page switching. But sometimes at random times if you use the back button, the HashTag changes in the browser, but the Whateverpage.Show is not called from the HashTagChanged event, and so it never switches pages.

Try what i’m suggesting. It was specifically added to be able to handle pressing of the back and forward buttons.

Basically the idea is that any time something significant happens that you want the user to be able to go “Back” to, you call SaveState. It also allows you to save some data which will be returned to you when the HashtagChanged event fires. (I tend to use JSON) The third parameter is for updating the current state. So if a user was on a page, lets say filling out a form, you could periodically update the current state so coming back to the page would not result in an empty form.

Okay, I’ll give it a try and see what it does for me. Thank you! I’ll update if it works!

So, I’m probably doing it wrong, because I couldn’t find any examples, and for some reason it took me some time to wrap my head around the concept, but, I did implement it in place of my calls to set the hashtag in the shown event for the pages, and it does seem to move a little smoother, but now I don’t have the forward button capability in the browser. Where should I be using the SaveState for these?

Call SaveState whenever you want to mark a place that users can go back to. It depends on your workflow, but it’s usually just before or just after changing pages.

Okay, that makes sense. Do you have any idea why it would be losing the forward arrow using it? I tried using it after switching pages and before.

The forward functionality will be lost as soon as you call SaveState again because none of the forward “history” is valid any more. FWIW, this is browser behavior, not Xojo.