简体   繁体   English

我需要打开一个页面,然后在一定时间后重新加载它

[英]I need to open a page then reload it after a certain amount of time

UPDATE: Thank you to everyone who answered. 更新:谢谢所有回答的人。 I learned I can't do exactly what I was trying to do. 我了解到我无法完全做到自己想做的。 Fortunately, I found some auto refresh extensions for Chrome that do what I wanted. 幸运的是,我发现了一些适用于Chrome的自动刷新扩展程序,它们可以满足我的要求。

Simple question. 简单的问题。 I don't code very much at all though. 我一点也不编写代码。 I'm trying to direct an html doc to immediately open a specific web page, then reload that same page in the same window after a specified amount of time. 我试图引导html文档立即打开特定的网页,然后在指定的时间后将其重新加载到同一窗口中。 The following code works, but opens a new window, which is NOT what I want: 以下代码有效,但是会打开一个新窗口,这不是我想要的:

<script>
    window.open('https://www.google.com');
    setTimeout('window.location.reload();', 10000);
</script>

Then I tried using the following: 然后我尝试使用以下内容:

<script>
    window.location.href='https://www.google.com';
    setTimeout('window.location.reload();', 10000);
</script>

But this only opens the page. 但这只会打开页面。 It does not reload it. 它不会重新加载它。 What am I doing wrong? 我究竟做错了什么? How do I do this right? 我该怎么做对?

Important Edit: 重要编辑:

This will only work if your code is at the arriving page. 仅当您的代码在到达页面时,此方法才有效。 You cannot open a window and launch some code in that one. 您无法打开一个窗口并在其中启动一些代码。


In both cases, the first line in your script does something first. 在这两种情况下,脚本的第一行都会先执行某些操作。

On the first case, it opens a new window then reload the page after ten seconds. 在第一种情况下,它将打开一个新窗口,然后在十秒钟后重新加载页面。

On the second case, it immediately goes to google. 在第二种情况下,它将立即转到google。

The second line should be enough to work. 第二行应足以工作。

Althought, I would advise you to do: 虽然如此,但我建议您这样做:

 setTimeout(function(){
     window.location.reload();
 }, 10000);

what you did is considered really bad practice. 您所做的被认为是非常糟糕的做法。

<script>
    window.location.href='https://www.google.com';
    setTimeout(function() {
       window.location.href='https://www.google.com';
    }, 10000);
</script>

Have you tried this? 你有尝试过吗?

I don't know if it helps, but maybe it's not a matter of reloading the page itself, but to run a function that updates some data in your view. 我不知道它是否有帮助,但是也许这不是重新加载页面本身的问题,而是要运行一个功能来更新视图中的某些数据。

暂无
暂无

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

相关问题 一定时间后重新加载某些div - Reload certain div after certain amount of time 经过一定时间后,如何停止刷新页面 - How can I stop a page from refreshing after a certain amount of time javascript 弹出页面加载时显示,然后经过一定时间后消失 - Pop up displaying on page load and then disappearing after I certain amount of time 在一段时间后只希望页面重定向到所需的链接 - Only want to page to redirect to desired link after a certain amount of time 在点击处理程序中经过一定时间后如何刷新页面 - how to refresh page after certain amount of time in click handler 如何在一定时间后基于php变量自动重新加载页面 - How to automatically reload page after a certain time based on a php variable 如何在访问者在页面上停留一段时间后才显示弹出窗口? - How do I make a pop-up that only appears after the visitor has been on the page for a certain amount of time? 如何在视频结束后将 HTML 页面上的元素替换为另一个元素,然后在一定时间后变回 - How to replace an element on a HTML page with another element after a video ends, then change back after a certain amount of time 检查滚动位置在顶部后,经过一段时间后将页面滚动到特定高度 - Making a page scroll to a specific height after a certain amount of time, after checking scroll position is at top 即使在页面重新加载后点击一段时间后禁用按钮 - Disabling button after click for a certain period of time even after page reload
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM