0

im having some Problems with my html/javascript project, while chrome seems fine with my code both firefox and ie deny to work how i want them to. Following you see the code which is causing trouble...

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

with

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 as well as desktopOutput only change the display values of some classes in my css document.

As i said chrome gets to the desktopOutput function but firefox and ie just log "DeviceOrientation is supported" then ignore the window.addEventListerner and keep going.

Thanks for any help!

Ascani0
  • 23
  • 3
  • add a console log at the very start of `handleOrientation` and include the values of the event.xxx in your if statement – Mark Schultheiss Feb 17 '16 at 17:15
  • @Mark I added a console log right at the start of handleOrientation, its logged in chrome but not in firefox or ie. To your second point, in which if statement should i include the values? – Ascani0 Feb 18 '16 at 10:47
  • I guess i was being dumb, im testing with my destop pc right now and while chrome seems to fire the deviceOrientation event with x,y and z = null firefox and ie just dont fire it at all. Howerer, thank you for your help :D – Ascani0 Feb 18 '16 at 11:02
  • what I referenced was the line `if(event.alpha!=null || event.beta!=null || event.gamma!=null) {` - what if those where all some other value like undefined etc. – Mark Schultheiss Feb 18 '16 at 16:02

0 Answers0