如何禁用方向横向应用程序和我们的网站

How to disable orientation Landscape in app and our website?

本文关键字:我们 网站 应用程序 何禁用 方向 横向      更新时间:2023-09-26

我想禁用取向:景观在我们的应用程序和网站使用jquery。所以请帮助我禁用应用程序和网站。

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

要做到这一点,需要媒体查询和检查方向的帮助,在横向样式表(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>
相关文章: