首页 > 解决方案 > Phaser 使用 Firefox(隐藏的 Iframe)崩溃到 null window.computedStyle()

问题描述

所有 Phaser 游戏引擎游戏似乎都会因以下错误而崩溃,但只有在iframe包含实际 Phaser 游戏的内容因显示游戏前视频广告而被隐藏时才使用 Firefox。

类型错误“window.computedStyle() 为空”

任何解决方法?

标签: javascriptphaser-framework

解决方案


我认为您拼错了错误:它是“window.getComputedStyle()”。

尝试使用这段代码:

    if (/firefox/i.test(navigator.userAgent)){
   window.oldGetComputedStyle = window.getComputedStyle;
   window.getComputedStyle = function (element, pseudoElt) {
      var t = window.oldGetComputedStyle(element, pseudoElt);
      if (t === null) {
         return {
            getPropertyValue: function(){}
         };
      } else{
         return t;
      }
   };
}

推荐阅读