javascript 视口大小改变时自动刷新页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12043956/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 15:09:26  来源:igfitidea点击:

Refreshing page automatically when viewport size change

javascripthtmlcss

提问by DextrousDave

I'm using responsive and adaptive media queries for my website to accommodate smartphones...Now the problem is that my max-width mobile query ends at 480px, which is most phones rotated display width (when the phone is on its side...). Now some phones, like the HTC desire have a max screen width of 533px, now when the user first loads the page on vertical position (320px screen width) and he/she rotates rotates the screen to 533px width, it goes past my design specifications and it looks kinda crappy...(since the layout was meant for 480px max...)

我正在为我的网站使用响应式和自适应媒体查询以适应智能手机......现在的问题是我的最大宽度移动查询以 480 像素结束,这是大多数手机旋转显示宽度(当手机侧放时.. .) 现在有些手机,比如 HTC 的愿望,最大屏幕宽度为 533px,现在当用户第一次在垂直位置(320px 屏幕宽度)加载页面并且他/她旋转将屏幕旋转到 533px 宽度时,它超过了我的设计规范它看起来有点蹩脚......(因为布局是为最大 480px 设计的......)

Now the only way to solve that is to refresh the page once the viewport dimensions change. How do I force a refresh?

现在解决这个问题的唯一方法是在视口尺寸发生变化时刷新页面。如何强制刷新?

Thank you

谢谢

回答by ILker ?zcan

if device rotate window resized.

如果设备旋转窗口调整大小。

window.onresize = function(event)
{
document.location.reload(true);
}