Javascript Orientation Change doesn't work with PhoneGap on iPad

前端 未结 1 950
梦毁少年i
梦毁少年i 2021-02-02 04:26

I\'m adapting a small HTML/CSS/Javascript driven web magazine as an iApp for the iPad with the great mobile framework PhoneGap. Everything works great, except the orientation ch

相关标签:
1条回答
  • 2021-02-02 05:02

    I just found an other solution to the problem. I use the body onload function with the onDeviceReady function from phonegap.js to check the orientations:

    The following javascript code works properly now:

        function onLoad() {
            document.addEventListener("deviceready", onDeviceReady, false);
        }
    
        function onDeviceReady() {
            document.addEventListener("orientationChanged", updateOrientation);
        }
    
        function updateOrientation(e) {
            switch (e.orientation) {
                case 90:
                    window.location = "index_landscape.html";
                    break;
                case -90:
                    window.location = "index_landscape.html";
                    break;
            }
        }
    

    UPDATE: This worked more than two years ago with old versions of Phonegap and iOS SDK, but according some users, it doesn't work anymore.

    0 讨论(0)
提交回复
热议问题