我搜索了可能解决此问题的方法,但到目前为止并没有获得太多乐趣。因此,也许您可​​以提供帮助;我为网站设计了一个移动版本,并且可以使用以下方法轻松地从主桌面布局中定位/重定向到该版本:

 // load Mobile version
  if (screen.width <= 999) {
window.location = "http://www.domain/test/Mobile/index.html";


}

在小型设备上访问网站时效果很好; (iPhone,纵向和横向的Android)或平板电脑(iPad,Kindle,纵向的Android)。

现在,当平板电脑(带有:(screen.width> = 1000))以横向访问网站时,我想回到桌面布局。

因此,在纵向模式下(保持移动版本布局),然后在旋转重定向(到桌面版本)时更适合横向查看。

知道我的编码是有限的,如何最好地做到这一点;-),或者如果已经有答案,请告诉我。

最佳答案

尝试使用@Felipe_Valencia提出的jQuery mobile (more info here)

<script src="code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
       //Don't forget to include these ^
<script>
    $( window ).on( "orientationchange", function( event ) {
      if (event.orientation == 'landscape' && screen.width>=1000){
          // load landscape version
          window.location = "http://www.domain/test/index.html";
      }
    });
</script>


编辑:



还有一个仅适用于Ipad的解决方案。
该脚本检测移动浏览器,但是我删除了检测iPad的部分。自己检查一下:

<script src="code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script>
//Don't forget to include these ^
$( window ).on( "orientationchange", function( event ) {
    if (event.orientation == 'landscape'){
         // load landscape version if not mobile browser (except the ipad one)
          if(!(/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) ) {
              window.location = "http://www.domain/test/index.html";
          };
    };
});
</script>


希望能有所帮助:)

关于javascript - 在设备旋转时使用javascript或CSS从纵向/横向重定向,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35142469/

10-12 00:07
查看更多