繁体   English   中英

如何在屏幕尺寸上将html文件更改为另一个html文件?

[英]How to change html file to another html file on screen size?

我的目标是,当您将屏幕尺寸更改为手机的尺寸(宽度方向)时,会得到不同的html文件或类似的文件。

如前所述,您应该真正使用媒体查询和响应式开发来获得所需的结果。

但是,如果您确定某些特定页面仅需要使用其他页面,则可以使用以下内容:

<script type="text/javascript">

var doRelocation = function() {

    var currentWidth = window.innerWidth,
        breakpoint = 800,
        newLocation = 'new-page.html';

    if (currentWidth < breakpoint) {
        window.location.replace(newLocation);
    }

}

doRelocation();

window.addEventListener('resize', doRelocation);

</script>

该脚本非常基本,但是该函数会在加载时运行以确定屏幕宽度以及调整大小。 它只能在现代浏览器中使用,但我想运行IE8的小屏幕设备并不多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM