Start and stop javascript update

I have a page that needs to be updated every 60 seconds. On this page, I use iBox to display various elements. My problem is that a meta update kills a popup that is not required. Please keep in mind that I have zero experience with javascript, so my solution may be fundamentally wrong.

The solution I came across is to use javascript to update. When the page loads, I started the timer, when ibox appears, I will clear the timer, when ibox closes, I started the timer again.

I configure this using a simple function.

function timedRefresh (timeoutPeriod) {
    var resetId = 0;
    resetId = setTimeout ("location.reload (true);", timeoutPeriod);
}

Then I call the function <body onload="timedRefresh(60000)">.

My problem is when I try to call clearTimeout(resetID). I am trying to call a method from the ibox script hide function, but it does not actually clear the timer. I think this may be a problem with the area, and I might need to do something like Object.clearTimeout(Object.resetID), but this is just an assumption.

+3
source share
4 answers

Do it:

function timedRefresh(timeoutPeriod){
    window.resetId = 0; // make it clear it global by prefixing "window."
    window.resetId=setTimeout("location.reload(true);",timeoutPeriod);
}

Then from the corresponding ibox function use window.resetId.


When I see your comment, I’ll add something.

"window". will work when writing scripts in a browser, if you use JS somewhere else, this probably won't work.

-, "". - - , ; , , "". .

, , resetId - var, , ​​ var, .

, Javascript, . , Jinjavas .

+1

- resetId :

var resetId = 0;
function timedRefresh(timeoutPeriod){
    resetId=setTimeout("location.reload(true);",timeoutPeriod);
}

iBox , , iBox.

: http://javascript.about.com/library/bltut07.htm

0

, resetId. var, , , .

resetId , , :

var resetId = 0;
function timedRefresh(timeoutPeriod){
    resetId=setTimeout("location.reload(true);",timeoutPeriod);
}
0

I suggest making the content on the page that needs to be updated, updated using ajax. Here is a link to a tutorial http://www.w3schools.com/Ajax/Default.Asp

0
source

Source: https://habr.com/ru/post/1726348/


All Articles