ratchet icon indicating copy to clipboard operation
ratchet copied to clipboard

Periodically refreshing a page

Open hgrecco opened this issue 10 years ago • 7 comments

What is the right way to periodically reload a page? I guess that <META HTTP-EQUIV="refresh" CONTENT="300"> is not the right way because it bypass push.js, right?

hgrecco avatar Aug 03 '15 15:08 hgrecco

Did you tried setInterval, setTimeout funcitons in jQuery?

setInterval(function(){ // Your code goes here }, 3000);

nbadiganti avatar Aug 05 '15 10:08 nbadiganti

I might be wrong but this seem be refreshing the whole page and thereby bypasses push.js

hgrecco avatar Aug 05 '15 22:08 hgrecco

Why not use AJAX instead of refreshing the entire page?

cvrebert avatar Aug 06 '15 19:08 cvrebert

@cvrebert I could, but I have a working frontend and backend to which I only need to add this feature. I was hoping that you could do a refresh via push that keeps the same behavior as it happens when I click a link.

hgrecco avatar Aug 07 '15 02:08 hgrecco

Just use the setInterval-function and place a manual call to the push-function inside:

PUSH({ url: /* your url */, transition : "fade" });

available transitions: "fade", "slide-in" or "slide-out"

garee76 avatar Aug 11 '15 06:08 garee76

@garee76 This works. Thanks a lot. My only problem now is that I need to cancel the timeout when I navigate out because it keeps refreshing to the same url.

hgrecco avatar Aug 15 '15 21:08 hgrecco

When calling PUSH like this you may want to set the ignorePush property to true so that it doesn't add the refresh to the browser history. Otherwise if the user hits their back button they'd just stay on the same page.

ronmichael avatar Aug 15 '15 23:08 ronmichael