使用js刷新间隔页面

时间:2023-01-20 20:48:53

How can i refresh a page for every one minute using javascript. Note: I don't have control/option to edit HTML body tag (where we usually call onload function).

如何使用javascript每隔一分钟刷新一次页面。注意:我没有控制/选项来编辑HTML body标签(我们通常称之为onload函数)。

4 个解决方案

#1


27  

Just insert this code anywhere in the page:

只需在页面中的任何位置插入此代码:

<script type="text/javascript">
  setTimeout(function(){
    location = ''
  },60000)
</script>

#2


18  

<script type="text/javascript">
    setTimeout(function () { 
      location.reload();
    }, 60 * 1000);
</script>

setTimeout will reload the page after a specified number of milliseconds, hence 60 * 1000 = 1m. Also, since the page is being refreshed, the timeout will always be set on page load.

setTimeout将在指定的毫秒数后重新加载页面,因此60 * 1000 = 1m。此外,由于页面正在刷新,因此将始终在页面加载时设置超时。

#3


8  

You do not need to have the code in the body tag. Just add this snippet below and it should work no matter where it is in the page.

您不需要在body标签中包含代码。只需在下面添加此代码段,无论页面中的位置如何,它都应该可以正常工作。

<script type="text/javascript">
    setInterval('window.location.reload()', 60000);
</script>

As long as you can access the HTML some where and your editor doesn't filter out tags you should be fine. If your editor has a separate area for JavaScript code then just enter setInterval line. :)

只要你可以在某些地方访问HTML并且你的编辑器没有过滤掉标签你应该没问题。如果您的编辑器有一个单独的JavaScript代码区域,那么只需输入setInterval行。 :)

#4


0  

When your URL has parameters, it seems that using location = '' doesn't work in IE8. The page reloads without any parameters.

当您的URL有参数时,似乎使用location =''在IE8中不起作用。页面重新加载没有任何参数。

The following code works for me :

以下代码适用于我:

<script type="text/javascript">
  setTimeout(function(){
      window.location.href = window.location.href;
  },10000)
</script>

#1


27  

Just insert this code anywhere in the page:

只需在页面中的任何位置插入此代码:

<script type="text/javascript">
  setTimeout(function(){
    location = ''
  },60000)
</script>

#2


18  

<script type="text/javascript">
    setTimeout(function () { 
      location.reload();
    }, 60 * 1000);
</script>

setTimeout will reload the page after a specified number of milliseconds, hence 60 * 1000 = 1m. Also, since the page is being refreshed, the timeout will always be set on page load.

setTimeout将在指定的毫秒数后重新加载页面,因此60 * 1000 = 1m。此外,由于页面正在刷新,因此将始终在页面加载时设置超时。

#3


8  

You do not need to have the code in the body tag. Just add this snippet below and it should work no matter where it is in the page.

您不需要在body标签中包含代码。只需在下面添加此代码段,无论页面中的位置如何,它都应该可以正常工作。

<script type="text/javascript">
    setInterval('window.location.reload()', 60000);
</script>

As long as you can access the HTML some where and your editor doesn't filter out tags you should be fine. If your editor has a separate area for JavaScript code then just enter setInterval line. :)

只要你可以在某些地方访问HTML并且你的编辑器没有过滤掉标签你应该没问题。如果您的编辑器有一个单独的JavaScript代码区域,那么只需输入setInterval行。 :)

#4


0  

When your URL has parameters, it seems that using location = '' doesn't work in IE8. The page reloads without any parameters.

当您的URL有参数时,似乎使用location =''在IE8中不起作用。页面重新加载没有任何参数。

The following code works for me :

以下代码适用于我:

<script type="text/javascript">
  setTimeout(function(){
      window.location.href = window.location.href;
  },10000)
</script>