Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/excaliburjs/Excalibur. 🎮 Your friendly TypeScript 2D game engine for the web 🗡️ excaliburjs.com
excalibur excaliburjs game-development game-engine game-framework gamedev games html5-canvas typescript
Something went wrong. Try again.
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546import { Logger } from './log';
/** * Checks if excalibur is in a x-origin iframe */export function isCrossOriginIframe() { try { // Try and listen to events on top window frame if within an iframe. // // See https://github.com/excaliburjs/Excalibur/issues/1294 // // Attempt to add an event listener, which triggers a DOMException on // cross-origin iframes const noop = () => { return; }; window.top!.addEventListener('blur', noop); window.top!.removeEventListener('blur', noop); } catch { return true; } return false;}
export function isIframe() { return window !== window.top;}
/** * Grabs the default global object for Excalibur */export function getDefaultGlobal(): GlobalEventHandlers { let global: GlobalEventHandlers; if (isCrossOriginIframe()) { global = window; Logger.getInstance().warnOnce('Excalibur might be in a cross-origin iframe, in order to receive keyboard events it must be in focus'); } else if (isIframe()) { global = window; Logger.getInstance().warnOnce('Excalibur might be in a iframe, in order to receive keyboard events it must be in focus'); } else { global = window.top!; }
return global;}