如何在调整大小时刷新页面?
是否有脚本可以在调整页面大小时使浏览器刷新?更具体地说,是模拟浏览器刷新按钮或 F5 的按钮吗?我找到了两个,但它们并不能完全满足我的要求;
<script type="text/javascript">
var currheight = document.documentElement.clientHeight;
window.onresize = function(){
if(currheight != document.documentElement.clientHeight) {
location.replace(location.href);
}
}
</script>
这两个的问题是
<body onResize="window.location=window.location;">
它们似乎完全重置了页面,因为使用浏览器刷新功能使一些用户所做的更改完好无损(例如处于特定的哈希值),这正是我所需要的。
那么有没有一种方法可以使用类似于单击浏览器刷新的脚本在调整大小时刷新窗口?我不明白为什么会有差异,但确实存在。
谢谢。
Is there a script to make the browser refresh when a page is re-sized? More specifically, one that emulates the browser refresh button or F5? I've found two, but they don't quite do what I'm looking for;
<script type="text/javascript">
var currheight = document.documentElement.clientHeight;
window.onresize = function(){
if(currheight != document.documentElement.clientHeight) {
location.replace(location.href);
}
}
</script>
and
<body onResize="window.location=window.location;">
The problem with these two is they appear to completely reset the page where as using the browsers refresh function leaves some user made changes intact (like being at a specific hash for instance) which is what I need.
So is there a way to refresh the window on re-size with a script similar to if the browser refresh was clicked? I don't understand why there is even a difference but there is.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可能想查看一些 JavaScript 事件。有一个 OnResize 事件。
以下是帮助您开始活动的链接:
http://www.devarticles.com /c/a/JavaScript/OnReset-OnResize-and-Other-JavaScript-Events/
至于重新加载页面,您也可以这样做:
http://www.mediacollege.com/internet/javascript/page/reload。 html
至于保留用户值,您可以将它们保留在会话中。
Yes, you probably want to take a look at some JavaScript events. There is an OnResize event.
Here's a link to get you started with events:
http://www.devarticles.com/c/a/JavaScript/OnReset-OnResize-and-Other-JavaScript-Events/
As far as reloading the page, you can do that too:
http://www.mediacollege.com/internet/javascript/page/reload.html
As far as keeping the user values, you could persist them in a session.
这是完美的解决方案:
我已经添加了 1 秒的超时,即浏览器将在窗口大小调整 1 秒后刷新
,没有超时
注意:您也可以使用
window.location.reload()
而不是window.location.href = window.location.href
window.location.reload()
重新加载当前页面对于 POST 数据,while
window.location.href=window.location.href
不包含 POST 数据-- 希望有帮助
Here is the perfect solution :
I have included timeout of 1 sec i.e. browser will refresh after 1 sec of window resize
Without timeout
NOTE : You may also use
window.location.reload()
instead ofwindow.location.href = window.location.href
window.location.reload()
reloads the current page with POST data,while
window.location.href=window.location.href
does not include the POST data-- hope it helps
试试这个:
Try this: