0

I want my html code to open the Google Page and refresh it after every 5 seconds. The Code i have written, it opens the google page after 5 seconds but it doesn't refresh or reload it again. How can I do that?

Here is the Code:

<html>

<head> 
    <script>

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

    </script>   

</head>

<body>

</body>
</html>
Oshadha
  • 546
  • 10
  • 25

3 Answers3

0

when you refresh the webpage by javascript, the browser will be redirected to google.com and would not be able to read your code. So the best way to this is to create a iframe in your html, and reload it by javascript.

because the reloading a iframe would not redirect your whole page to a new domain, your js code will still exist and able to run :

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

Take away the semi colon after your Web address and remove the javascript entirely

Rmj86
  • 1,140
  • 1
  • 7
  • 9
-1

You will need to have Google in an iframe then have the following code in you HTML file head:

   <head>
<meta http-equiv="refresh" content="5">
</head>
Rmj86
  • 1,140
  • 1
  • 7
  • 9