Browser button javascript

Hi there,

Is there a way that I can use javascript which will detect when the browsers back button has been pressed which will then go to a certain scene.

Thanks Ollie

Hi Ollie

Try looking at the “History API” for HTML5.

You can manipulate the history using this I believe it will help you on your way. Not sure how it would call a scene but I guess you can use the showSceneNamed() function to do this inside the javascript.

Hope this helps!


I think all of the scenes in Hype are actually on the same webpage, so the browser’s back/forward buttons are not active.

Hi Greg, I have read around a bit and it seems that is the way. So I was hoping / thinking that some code could be manually added per scene so the back and forwards can be used to an extent to go forward and back.

I wouldn’t be so concerned, but there are many users who regularly use the default browser buttons, so I believe it is a feature which should really be included in my website.

Thanks Ollie

Here’s one way:

Run this function ‘on scene unload’

window.lastHypeSceneName = hypeDocument.currentSceneName();

And use this script when clicking the ‘back’ button:

if (window.lastHypeSceneName == undefined)
// do nothing.
    // If you want to create a 'forward' button, you would need to capture this variable: 
    // window.ExitedSceneName = hypeDocument.currentSceneName();
hypeDocument.showSceneNamed(window.lastHypeSceneName, kSceneTransitionCrossfade);

The first ‘if’ ensures that there isn’t a Javascript error if no scene has been visited yet. (14.9 KB)

using this: Linking to a specific scene from inside and outside of a Tumult Hype document

will add #name-of-scene to the url and you’ll be able to navigate with back and forward browser buttons, if that’s what you need.


Hi there,

Sorry for the very slow reply, but I have tried out your suggestion and followed the steps you linked.

It is working great! Thanks so much for you response.

Thanks Ollie