firefox中的事件监听器/即被忽略

时间:2016-02-17 16:34:11

标签: javascript html internet-explorer firefox events

我对我的html / javascript项目有一些问题,而chrome似乎很好,我的代码都是firefox,即拒绝工作我想要的方式。 下面你看到引起麻烦的代码...

<script>
    if (window.DeviceOrientationEvent) {
        console.log("DeviceOrientation is supported");
        window.addEventListener("deviceorientation", handleOrientation);
    } else {
        console.log("DeviceOrientation is not supported");
    }
</script>

var handleOrientation = function(event){
    if(event.alpha!=null || event.beta!=null || event.gamma!=null) {
        var alpha = Math.round(event.alpha);
        var beta = Math.round(event.beta);
        var gamma = Math.round(event.gamma);
        if (WURFL.form_factor == "Tablet") {
            tabletOutput();
        }
        orientationFunction(alpha, beta, gamma);
        if(navigator.userAgent.match(/Android/i)){
            document.getElementById("androidSpecial").style.display = "inline";
        }
    } else {
        desktopOutput();
    }
};

tabletOutput以及desktopOutput仅更改css文档中某些类的显示值。

正如我所说,chrome进入了desktopOutput函数,但是firefox就是log&#34;支持DeviceOrientation&#34;然后忽略window.addEventListerner并继续。

感谢您的帮助!

0 个答案:

没有答案