Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to avoid using innerHTML because it causes my browser to crash, probably due to the 250 milliseconds refresh rate.

Anyway, I would rather have some content in an hidden <div> and make the <div> visible only if a certain condition is met. What's the best approach to go around this?

Basically, what I'm doing now is..

setInterval(function () {
    if (serverReachable()) {
        .... // lines of code
        .... // lines of code
    var changeIt = document.getElementById('change')
    changeIt.innerHTML = '';
           timeout = setInterval(function(){window.location.href = "Tracker.html";},5000);
        }
    } else {
        clearTimeout(timeout);
        timeout = null;
    var changeIt = document.getElementById('change')
    changeIt.innerHTML = 'offline';
   }
}, 250);

This will crash my browser, because I'm not using innerHTML to print "offline" but a whole <div>. I want to have this <div> hidden, and instead of using innetHTML, to simply unhide if a condition is met (in this case, no internet connection).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Then use CSS to hide and unhide the div. You can do something like this:

    changeIt.style.visibility = 'hidden';

to make the div disappear. And

   changeIt.style.visibility = 'visible';

to show it again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...