javascript - 强制浏览器以纵向加载页面

标签 javascript jquery html css

我需要在手机和平​​板电脑上以纵向模式显示我的页面。我怎样才能强制浏览器以这个方向加载它。或者我怎样才能完全禁用横向方向?

最佳答案

你不能强制它:(

浏览器是移动设备上的应用程序,能够横向或纵向显示。

所以:您的问题可以重新问为:“是否可以要求浏览器仅以横向模式打开?”可能某些自定义页面指令可以告诉浏览器以横向模式打开自身(搜索也许你可以在这里找到一些东西!)

但是你可以使用 css 技巧(这不是推荐的方法),如 https://www.quora.com/Can-I-use-Javascript-to-force-a-mobile-browser-to-stay-in-portrait-or-landscape-mode 中提到的。

这个想法是在所有页面内容上使用CSS旋转

@media screen and (orientation:landscape) {
  //set you content id
  #container {
    -ms-transform: rotate(-90deg); /* IE 9 */
    -webkit-transform: rotate(-90deg); /* Chrome, Safari, Opera */
    transform: rotate(-90deg);
    width: /* screen width */ ;
    height: /* screen height */ ;
    overflow: scroll;
  }
}

我推荐 forcing web-site to show in landscape mode only 中提到的解决方案它轻轻地要求用户旋转浏览器(@JasonSebring)

<style type="text/css">
    #warning-message { display: none; }
    @media only screen and (orientation:portrait){
        #wrapper { display:none; }
        #warning-message { display:block; }
    }
    @media only screen and (orientation:landscape){
        #warning-message { display:none; }
    }
</style>

....

<div id="wrapper">
    <!-- your html for your website -->
</div>
<div id="warning-message">
    this website is only viewable in landscape mode
</div>

关于javascript - 强制浏览器以纵向加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32719012/

相关文章:

javascript - 根据母语人士的数量寻找一个好的 ISO 语言标签列表

javascript - AngularJS - 多重绑定(bind) - 计算输入值

html - 如何删除 Chrome 27 中日期时间本地 HTML 输入上的蓝色十字?

html - 如何防止此灯箱离开页面顶部?

javascript - 在 Vue 实例中混合响应式(Reactive)和非响应式(Reactive)数据会有害吗?

javascript - keyup 事件在动态生成 tr 元素后不起作用

jquery - 如何为表单的所有输入绑定(bind)一个事件?

Jquery多选

javascript - 如何使 fancyBox 2 调整其高度以适合其内容?

html - 如何在 MarkLogic 中保留 HTML5 文档类型?