Make a page refresh when it's closed on iPhone

I’m trying to figure out how I can make it so an animation doesn’t continue when someone closes out of Safari on the iPhone. I have a game that finishes the level if you leave safari and come back in a few minutes later. Is there anyway to either reset a scene when leaving the page or refreshing the page when you come back?

The Page Visibility API is probably what you want (I haven’t specifically tested for iOS brower show/hide, but I part of the main purpose is to do things like this!). It will require some javascript:

Basically, you’d listen to the event, and then can use the Hype JavaScript API to jump to a specific scene (or do things like pause timelines).


I could only find the exported Hype files within that zip. Do you mind attaching the Hype doc?

And after all that I cannot see how I read iOS app from > Safari on the iPhone

I think my brain farted on the word iPhone, and I need sleep… :flushed:.

Well I had fun going over iOS calls to Hype again but withdrawn those post as they are not relevant to this thread… sigh.

Here is a simple example of @jonathan 's idea.

testCall.hype (39.3 KB)

1 Like

Awesome, thank you! Works like a charm

How would I stop this function on scene unload? I have several levels in the game I’m making, and once the first JS function (for level 1) loads, it then starts applying it to other scenes and will reset and go back to the level 1 scene.

What do yo want it to do on the other scenes

Well I copied and pasted the code for the other levels, so same function except changed it to the appropriate scene… So for instance, here is a snippet of the end of the function you provided… This is for the scene “Level2”:

hypeDocument.showSceneNamed('Level2’, hypeDocument.kSceneTransitionCrossfade, 0.2);
} else {
hypeDocument.showSceneNamed(‘Level2’, hypeDocument.kSceneTransitionCrossfade, 0.2);

This function is called “levelTwoPause”… How would you “deactivate” this function?

Sorry that not really clear to me what your expecting.

But if its,

if we were on scene 1 then we return back to the start of scene 1.
if we were on scene 2 we return to the start of scene 2

We would use a single function for all relevant scenes.

	 window.current_Scene_Name = hypeDocument.currentSceneName();
	var hidden, visibilityChange; 
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
  hidden = "hidden";
  visibilityChange = "visibilitychange";
} else if (typeof document.mozHidden !== "undefined") {
  hidden = "mozHidden";
  visibilityChange = "mozvisibilitychange";
} else if (typeof document.msHidden !== "undefined") {
  hidden = "msHidden";
  visibilityChange = "msvisibilitychange";
} else if (typeof document.webkitHidden !== "undefined") {
  hidden = "webkitHidden";
  visibilityChange = "webkitvisibilitychange";
	document.addEventListener(visibilityChange, handleVisibilityChange, false);
  function handleVisibilityChange() {
  if (document[hidden]) {
   hypeDocument.showSceneNamed('splashScene', hypeDocument.kSceneTransitionCrossfade, 0.2);
  } else {
  hypeDocument.showSceneNamed( window.current_Scene_Name, hypeDocument.kSceneTransitionCrossfade, 0.2);

Gotcha! Sorry, I don’t know JS very well, so my alterations were just guesses. That makes sense though, thank you!

[quote=“MarkHunte, post:8, topic:7890”]
Well I had fun going over iOS calls to Hype again but withdrawn those post as they are not relevant to this thread… sigh.

Hi Mark,

How would I pause the animation in this example please? (8.8 KB)

Nevermind I did.