[英]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.