Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 自动重新加载谷歌页面_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 自动重新加载谷歌页面

Javascript 自动重新加载谷歌页面,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我希望我的html代码打开谷歌页面,每5秒刷新一次。 我写的代码在5秒钟后打开google页面,但不会再次刷新或重新加载。我该怎么做 代码如下: <html> <head> <script> setInterval(function(){ window.location.href ="https://www.google.com.pk/"; }, 5000); </script&g

我希望我的html代码打开谷歌页面,每5秒刷新一次。 我写的代码在5秒钟后打开google页面,但不会再次刷新或重新加载。我该怎么做

代码如下:

<html>

<head> 
    <script>

        setInterval(function(){
        window.location.href ="https://www.google.com.pk/"; 
        }, 5000);

    </script>   

</head>

<body>

</body>
</html>

setInterval(函数(){
window.location.href=”https://www.google.com.pk/"; 
}, 5000);

您需要在iframe中包含Google,然后在HTML文件头中包含以下代码:

   <head>
<meta http-equiv="refresh" content="5">
</head>

当您使用javascript刷新网页时,浏览器将重定向到google.com,无法读取您的代码。因此,最好的方法是在html中创建一个iframe,并通过javascript重新加载它

因为重新加载iframe不会将整个页面重定向到新域,所以js代码仍然存在并能够运行:

<html>
 <body>
  <iframe src="http://www.google.com" id="googleIframe"></iframe>
 <script>
document.getElementById('googleIframe').contentDocument.location.reload(true);
</script>
</body>
</html>

document.getElementById('googleIframe').contentDocument.location.reload(true);

删除网址后的分号,并完全删除javascript

您无法刷新非您自己的页面,除非它位于iframe中。你能解释一下iframe是什么意思吗?iframe是一个dom元素,它允许你在你的网页中显示另一个网页。好的,那么我是否可以使用iframe标记并将其引用到google。因此,它将在循环中重新加载google页面,对吗?是的,在我第一条评论中链接的问题中,看看一个很好的方法。答案是
使用iframe,并每5秒刷新一次。
这不是一个很好的解决方案,因为它需要刷新用户所在的整个页面。OP似乎要求使用HTML代码,但使用了JS,但失败了。这个问题是html唯一的解决方案。OP提出了一些不可能的问题,从他的代码中可以明显看出,他试图使用javascript,这个问题用javascript标记。这是我编写的代码。它没有显示谷歌页面。但它正在刷新document.getElementById('#googleIframe').contentDocument.location.reload(true);你的代码无法运行。您将得到一个错误:
Uncaught SyntaxError:Invalid或unexpected token
Sorry刚刚错过了getElementById中的字符串您可能还希望将刷新设置为OP的间隔。你那样做之后,我会+1它。