Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网站定位_Javascript_Android_Html_Ios - Fatal编程技术网

Javascript 网站定位

Javascript 网站定位,javascript,android,html,ios,Javascript,Android,Html,Ios,我有一个网站,这将是在手机上打开的大部分时间,我需要该网站在默认情况下以横向模式显示。(虽然用户处于纵向模式,但也应处于横向模式)。 请帮助我,使用哪种代码 我使用了这个代码,但它对我没有任何帮助 <script> var start = function() { screen.orientation.lock('landscape-primary').then( startInternal, function() { alert(

我有一个网站,这将是在手机上打开的大部分时间,我需要该网站在默认情况下以横向模式显示。(虽然用户处于纵向模式,但也应处于横向模式)。 请帮助我,使用哪种代码

我使用了这个代码,但它对我没有任何帮助

<script>
  var start = function() {
    screen.orientation.lock('landscape-primary').then(
      startInternal,
      function() {
        alert('To start, rotate your screen to landscape.');

        var orientationChangeHandler = function() {
          if (!screen.orientation.type.startsWith('landscape')) {
            return;
          }
          screen.orientation.removeEventListener('change', orientationChangeHandler);
          startInternal();
        }

        screen.orientation.addEventListener('change', orientationChangeHandler);
      });
  }
  window.onload = start;
</script>

var start=function(){
screen.orientation.lock('scarland-primary')。然后(
星际内部,
函数(){
警报('要开始,请将屏幕旋转到横向');
var-orientionChangeHandler=函数(){
如果(!screen.orientation.type.startsWith('scape')){
返回;
}
screen.orientation.removeEventListener('change',orientationChangeHandler);
startInternal();
}
screen.orientation.addEventListener('change',orientationChangeHandler);
});
}
window.onload=开始;

如果使用css,可能会更容易

@media (orientation: portrait) { 
    .reorientMessage{
        visibility: visible;
    }
    .mainContent{
        visibility: hidden ;
    }
}
@media (orientation: landscape) { 
    .reorientMessage{
        visibility: hidden;
    }
    .mainContent{
        visibility: visible ;
    }
}
html例如

<div class="reorientMessage">please reorient etc..</div>
<div class="mainContent">normal stuff here</div>
请重新定向等。。
这里是普通的东西

如果使用css,可能会更容易

@media (orientation: portrait) { 
    .reorientMessage{
        visibility: visible;
    }
    .mainContent{
        visibility: hidden ;
    }
}
@media (orientation: landscape) { 
    .reorientMessage{
        visibility: hidden;
    }
    .mainContent{
        visibility: visible ;
    }
}
html例如

<div class="reorientMessage">please reorient etc..</div>
<div class="mainContent">normal stuff here</div>
请重新定向等。。
这里是普通的东西

您是否使用Webview在手机上显示网站?我不知道如何使用它,我只是使用简单的HTML作为常规。为什么不使用css媒体查询?您是否使用Webview在手机上显示网站?我不知道如何使用它,我只是使用简单的HTML作为常规。为什么不使用css媒体查询?它在某种程度上帮助了我,但它迫使用户重新定位。我需要的网站只在景观。看起来这可能是你想要的:可能有其他问题,如用户的设备/设置是否允许重新定位,设备上的webkit版本是否支持它没有错误等。所以回答你的OP具体-为什么代码不为你工作有点困难(也就是说,它怎么会对你不起作用呢?)所以我在这里插嘴:)它在某些方面帮助了我,但它迫使用户重新定位。我需要的网站只在景观。看起来这可能是你想要的:可能有其他问题,如用户的设备/设置是否允许重新定位,设备上的webkit版本是否支持它没有错误等。所以回答你的OP具体-为什么代码不为你工作有点困难(也就是说,这怎么对你不起作用呢?)所以我在这里闭嘴:)