How to make scene refresh when browser back button activated

Hi,

I am sure I have seen this somewhere in the forum but am unable to find this.

I have a page with a # parameter and this is changed programmatically via JS in the scene, however when the user uses the back button while the URL is changed the scene is not, is there a way to monitor or refresh the scene?

Thanks in advance.

create a function onLoad:
/*
hypeDocument - access to the hype document API:
METHODS:
hypeDocument.documentName()
hypeDocument.sceneNames()
hypeDocument.currentSceneName()
hypeDocument.showSceneNamed(sceneName, optionalTransition)
hypeDocument.showNextScene(optionalTransition)
hypeDocument.showPreviousScene(optionalTransition)
hypeDocument.playTimelineNamed(timelineName)
hypeDocument.getElementById(id)

					MORE INFO:
					http://tumultco.com/hype/documentation/javascript/

	element - DOMHTMLElement that triggered this function being called
	event - event that triggered this function being called
*/

var checkHash = function() { 
var hash = window.location.hash.substring(1); 
if(hypeDocument.sceneNames().indexOf(hash) != -1) { 
hypeDocument.showSceneNamed(hash); 
} 
}; 

if (window.loadedHashLocation != true) { 
window.loadedHashLocation = true; 
checkHash(); 
window.onhashchange = checkHash; 
} 

window.location.hash = "#" + hypeDocument.currentSceneName();

this will reload the current scene.
if you want to create auto-reload, create a timeline, and put in a keyframe with function:

if(!window.location.hash) {
    window.location = window.location + '#loaded';
    window.location.reload();
}

then loop this timeline.

2 Likes