Javascript orientation change does not work with PhoneGap on iPad

I am adapting a small HTML / CSS / Javascript based weblog like iApp for iPad with the excellent PhoneGap mobile map. Everything works fine, except for changing orientation from portrait to landscape mode.

I use the following Javascript code in the index.html (portrait) header:

  var isiPad = navigator.userAgent.match(/iPad/i) != null;
  var isiPhone = navigator.userAgent.match(/iPhone/i) != null;

  function updateOrientation() {
   if (isiPad || isiPhone) {
    switch (window.orientation) {
     case 90:
      window.location = "index_landscape.html";
      break;
     case -90:
      window.location = "index_landscape.html";
      break;
    }
   }
  }

with the following body tag:

<body onorientationchange="updateOrientation();">

If I turned iPad into landscape mode, it will not change to index-landscape.html.

Does anyone know where the problem is? Is it not possible to change the HTML file when changing the orientation within PhoneGap? In other words, can I use one HTML file (index.html) using PhoneGap and use CSS to change the orientation?

- Safari iPad, .

!

+3
1

. onload onDeviceReady phonegap.js :

javascript :

    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;
        }
    }

: Phonegap iOS SDK, , , .

+3

Source: https://habr.com/ru/post/1761107/


All Articles