使用 javascript 或 jquery 在调整大小时刷新页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14915653/
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
Refresh page on resize with javascript or jquery
提问by supersize
I want to force the browser to refresh the page when the user resizes it. I have following code:
我想强制浏览器在用户调整页面大小时刷新页面。我有以下代码:
function refresh() { location.reload(); }
<body onResize="refresh()">
but it does not work. Does anyone of you has a solution? Thanks
但它不起作用。你们中有人有解决方案吗?谢谢
回答by Phillip Schmidt
Do it with javascript/jquery:
用 javascript/jquery 来做:
just javascript:
只是javascript:
window.onresize = function(){ location.reload(); }
with jquery:
使用 jquery:
$(window).resize(function(){location.reload();});
or
或者
$(window).on('resize',function(){location.reload();});
回答by JCBrown
The following code seems to work with all browsers,
以下代码似乎适用于所有浏览器,
$(window).bind('resize', function(e)
{
if (window.RT) clearTimeout(window.RT);
window.RT = setTimeout(function()
{
this.location.reload(false); /* false to get page from cache */
}, 100);
});
Hope it helps everyone. I found this information here: http://www.jquery4u.com/snippets/jquery-refresh-page-browser-resize/
希望对大家有帮助。我在这里找到了这个信息:http: //www.jquery4u.com/snippets/jquery-refresh-page-browser-resize/
回答by henser
try this:
尝试这个:
$(window).resize(function() {
location.reload();
});

