Browser button javascript

knowledgebase

(Ollie) #1

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


#2

Hi Ollie

Try looking at the “History API” for HTML5.

http://diveintohtml5.info/history.html

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!

D


(Greg) #3

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


(Ollie) #4

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


#5

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.
}
else{
    // 
    // 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.

backtopreviousscene.hype.zip (14.9 KB)


(ocultor) #6

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.


(Ollie) #7

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