Browser reload/refresh stay on current scene

(Troy N.) #1

I am working on my new website that is made up of several scenes. My only concern about it is if someone reloads the web browser in one of the scenes, it will then take them back to the “homepage” or main scene. Is there a way or code that when or if they click on the reload/refresh button they stay on the current scene?

(Mark Hunte) #2

You would need distinguish between a navigational click and a browser reload.

A nav click to go to another scene will trigger an onload event.
Reloading the browser will trigger an onload event.

You can distinguish easy enough by having the clicks trigger a function which set a global bool variable.
Thats the easy part. But when your browser reload syou will loose the global vars so you most likely will need to use window.sessionStorage to store the current scene.

All this can be done, and off the top of my head here is an example. (34.1 KB)

A simpler way is to run javascript that sets the page address to the scene name as a anchor ‘#’

Then all you need to worry about is what scene names to use. The browser will naturally reload the current scene because it is reloading aa anchor.

The Tumult team have posted a simple way of doing this.

The first section on that page Linking to a Scene using an URL is the part you want.
Testing it it works well.

(Troy N.) #3

Thank you for the reply. I will play around with the anchors, and javascript a bit. What you said makes sense.