diff --git a/src/core/scene/a-scene.js b/src/core/scene/a-scene.js index 27428ec016f..4f1f0caf202 100644 --- a/src/core/scene/a-scene.js +++ b/src/core/scene/a-scene.js @@ -74,6 +74,10 @@ module.exports.AScene = registerElement('a-scene', { }); this.addFullScreenStyles(); initPostMessageAPI(this); + + // Handler to exit VR (e.g., Oculus Browser back button). + this.exitVRBound = bind(this.exitVR, this); + window.addEventListener('onvrdisplaydeactivate', this.exitVRBound); }, writable: true }, @@ -131,16 +135,20 @@ module.exports.AScene = registerElement('a-scene', { */ detachedCallback: { value: function () { + var sceneIndex; + if (this.effect && this.effect.cancelAnimationFrame) { this.effect.cancelAnimationFrame(this.animationFrameID); } else { window.cancelAnimationFrame(this.animationFrameID); } - var sceneIndex; this.animationFrameID = null; + // Remove from scene index. sceneIndex = scenes.indexOf(this); scenes.splice(sceneIndex, 1); + + window.removeEventListener('onvrdisplaydeactivate', this.exitVRBound); } },