This question already has answers here:
Mobile site - force landscape only / no auto-rotate
                            
                                (5个答案)
                            
                    
                    
                        Disable landscape-mode for mobile devices
                            
                                (2个答案)
                            
                    
                3年前关闭。
        

    

我想禁用方向:使用jQuery在我们的应用程序和网站中的风景。
所以请帮助我在应用程序和网站上禁用。

最佳答案

我不确定是否可以使用,但请尝试一下

<head>
<style type="text/css">
#landscape{
         position: absolute;
         top: 0px;
         left: 0px;
         background: #000000;
         width: 100%;
         height: 100%;
         display: none;
         z-index: 20000;
         opacity: 0.9;
         margin:0 auto;
}
#landscape div{

        color: #FFFFFF;
        opacity: 1;
        top: 50%;
        position: absolute;
        text-align: center;
        display: inline-block;
        width: 100%;
}
</style>
<script>
      function doOnOrientationChange()
      {
        switch(window.orientation)
        {
          case -90:
                 document.getElementById("landscape").style.display="block";
                 break;
          case 90:
                document.getElementById("landscape").style.display="block";
                break;
         default:
                document.getElementById("landscape").style.display="none";
                break;
        }
      }

      //Listen to orientation change
      window.addEventListener('orientationchange', doOnOrientationChange);

    </script>
</head>
<body onload="doOnOrientationChange();">
<div id="landscape"><div>"Rotate Device to Portrait"</div></div>
</body>

10-04 15:23