如何在应用程序和我们的网站中禁用方向景观?

How to disable orientation Landscape in app and our website?

我想使用 jquery 在我们的应用和网站中禁用 orientation:Landscape。 所以请帮我在应用程序和网站中禁用。

抱歉,您不能在网页上强制方向,但是当用户处于横向模式时,您可以在内容中显示一些信息。

要做到这一点借助媒体查询并检查方向,在横向样式表 (style_landscape.css) 中隐藏所有内容并显示一条消息,您的应用可以'无法在横向模式下打开,用户必须恢复为纵向模式才能继续。

<link rel="stylesheet" type="text/css" href="css/style_landscape.css" media="screen and (orientation: landscape)">
<link rel="stylesheet" type="text/css" href="css/style_portrait.css" media="screen and (orientation: portrait)">

我不确定它是否有效,但试试这个

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