Получить ландшафтный / портретный режим с помощью PHP - PullRequest
1 голос
/ 20 февраля 2012

Есть ли способ восстановить режим смартфона?Если это в ландшафтном или портретном режиме?И все, что доступно в PHP?

Кажется, Session не может быть доступен в JS.Но вы можете сделать это с Cookies.Вот фрагмент (не тестировался)

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/; domain=.example.com";
}
function eraseCookie(name) {
createCookie(name,"",-1);
}

window.onorientationchange = function() {
  /*window.orientation returns a value that indicates whether iPhone is in portrait mode, landscape mode with the screen turned to the
left, or landscape mode with the screen turned to the right. */
var orientation = window.orientation;

switch(orientation) {

 case 0:
    // If in portrait mode
    document.getElementById("google_map").style.width="300px";
    document.getElementById("google_map").style.height="200px";
  eraseCookie("orientation"); 
   createCookie('orientation','portrait','0');
    break;  

case 90:
    // If in landscape mode with the screen turned to the left
    document.getElementById("google_map").style.width="450px";
    document.getElementById("google_map").style.height="325px";
  eraseCookie("orientation");
    createCookie('orientation','landscape','0');
    break;

case -90:  
    // If in landscape mode with the screen turned to the right
    document.getElementById("google_map").style.width="450px";
    document.getElementById("google_map").style.height="325px";
  eraseCookie("orientation");
    createCookie('orientation','landscape','0');
    break;

case 180:
    // If in portrait mode with the screen flipped
    document.getElementById("google_map").style.width="300px";
    document.getElementById("google_map").style.height="200px";
  eraseCookie("orientation");
    createCookie('orientation','portrait','0');
    break;
  }
}

В PHP:

 $orientation = $_COOKIE["orientation"];
 if($orientation=="portrait"){
     // do something
}else if($orientation=="landscape"){
    // do something different
}else{
  // fallback
 }

Взят из здесь и здесь и здесь и здесь и здесь .

1 Ответ

1 голос
/ 20 февраля 2012

Максимум, что вы можете сделать, это обнаружить в Javascript и затем отправить эти данные обратно на сервер. Проверьте window.orientation и событие orientationchange.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...