0

My aim is to reload a page at a certain interval and run a function. I have read about storing the function in my localStorage and calling it when the page reloads via body onload. I wish to run this code on my console on a page so I don't think the <body> works. Correct me if I am wrong.

A good example would be, continued reloading of a Ebay page and it gets the prices of all toys, then it reloads and gets the price again and it continues to reload till I close the browser. But every time I reload I can't run my function.

All help is appreciated, for my understanding.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • This comment does not shows how to do this in javascript but I feel approach to solve the problem can be improved. Why not write a program in your choice of language, read that url, get the content as string/xml/html, parse it, collect the values, save/use them, make the thread sleep, re-read the page. You can take help from this http://stackoverflow.com/questions/4328711/read-url-to-string-in-few-lines-of-java-code – Ravi Kumar Gupta Apr 30 '16 at 09:43

5 Answers5

0

Small example:

var 
  ready = function() {
  
  setTimeout(function() {
    
    //alert('Yay!');
    location.reload();
    
  }, 3000); // 3000 ms => 3 seconds
};
<body onload="ready()">
  <h1>Page!</h1>
</body>
Ali Mamedov
  • 5,116
  • 3
  • 33
  • 47
0
$(window).bind("load", function() {
    // code here
});
Thomas Bormans
  • 5,156
  • 6
  • 34
  • 51
jamal zareie
  • 19
  • 1
  • 5
0

If I understand you correctly, you want to run some script at the third-party website (e.g. Ebay), reload page and do it all again.

You can use some browser extensions. For example, that one.
This extension detect page URL and runs any script you have written for it.
So, your script automatically runs by extension, do some work, reloads page and then repeats all.

// script runs automatically by extension:
$( function() {
    // do some work:
    /* some work */

    // and then reloads page:
    location.reload();
} );
Legotin
  • 2,378
  • 1
  • 18
  • 28
0

You can do this with the setinterval function. It will repeat something afer a certain amount of time.

For the reload, its not really needed as you can call a ajax request and just change the parts that is needed.

example :

 setInterval(function () { alert("Hello"); }, 3000);

It will alert out Hello every 3 secounds

stian64
  • 1,563
  • 3
  • 12
  • 25
0

100% working. :)

<html>
<head>
<meta http-equiv="Refresh" content="10">

<script type="text/javascript">
var whenready = function() {

        alert('It Works Man..!!');
    };

</script>
</head>
    <body onLoad="whenready()">
      <h1>Page!</h1>
    </body>
</html>
Jet lee
  • 58
  • 7