How to close WebGL App?

I’ve got my game loaded in a web page div. However, I need to control when it loads & when it closes.

I can start the game on command fine. However, what is the proper way to end it? Application.Quit is ignored apparently.

I tried just simply disposing but it ended up aww snapping the browser.

There are a few functions on:

gameInstance.Module

But it doesn’t seem like you can actually call, quit, exit or abort…

Bit of a hack, but iFrame does the trick.

Rename index.html to game.html.

create a new index.html.

<!DOCTYPE html>
<html lang="en-us">

<head>
  <meta charset="utf-8">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Game Container</title>
  <style>
    body {
      margin: 0;
      padding: 0;
      background-color: white;
      overflow: hidden;
    }

    #canvas {
      width: auto;
      height: 100vh;
      display: block;
    }
  </style>

  <script>
    function removeElement(element) {
      element && element.parentNode && element.parentNode.removeChild(element);
    }

    function onPlayClicked() {
      document.getElementById('iframeDiv').src = "./game.html";
    }

    function onQuitClicked() {
      document.getElementById('iframeDiv').src = "";
    }
  </script>
</head>

<body>
  <div id="controls" style="position: absolute;">
    <button style="position: relative;" onclick="onPlayClicked()">Play</button>
    <button style="position: relative;" onclick="onQuitClicked()">Quit</button>
  </div>
  <iframe id="iframeDiv" style="width: 100vw; height: 100vh; z-index: 0;" src=""></iframe>
</body>

</html>

Should be able to Play/Reload/Quit the game… Also disables audio.

127766-webgl-iframe.gif