如何在调整大小时刷新页面?

发布于 2024-08-13 01:36:53 字数 601 浏览 4 评论 0原文

是否有脚本可以在调整页面大小时使浏览器刷新?更具体地说,是模拟浏览器刷新按钮或 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一绘本一梦想 2024-08-20 01:36:53

是的,您可能想查看一些 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.

暮年 2024-08-20 01:36:53

这是完美的解决方案:

我已经添加了 1 秒的超时,即浏览器将在窗口大小调整 1 秒后刷新

$(window).resize(function() {
    setTimeout( function(){
        window.location.href = window.location.href;
    },1000); 
});

,没有超时

$(window).resize(function() {
    window.location.href = window.location.href;
});

注意:您也可以使用
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

$(window).resize(function() {
    setTimeout( function(){
        window.location.href = window.location.href;
    },1000); 
});

Without timeout

$(window).resize(function() {
    window.location.href = window.location.href;
});

NOTE : You may also use
window.location.reload() instead of window.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

手心的海 2024-08-20 01:36:53

试试这个:

<![if !IE]> <body onresize="document.location=window.location;"> <![endif]>
<!--[if IE]> <body onresize="window.location.reload();"> <![endif]-->

Try this:

<![if !IE]> <body onresize="document.location=window.location;"> <![endif]>
<!--[if IE]> <body onresize="window.location.reload();"> <![endif]-->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文