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 would like to implement a JavaScript code which states this: if the page is loaded completely, refresh the page immediately, but only once.

(我想实现一个JavaScript代码,该代码声明:如果页面已完全加载,请立即刷新页面,但只刷新一次。)

I'm stuck at the "only once":

(我被困在“只有一次”:)

window.onload = function () {window.location.reload()}

this gives a loop without the "only once".

(这给出了一个没有“只有一次”的循环。)

jQuery is loaded if this helps.

(如果这有帮助,加载jQuery。)

  ask by Martin translate from so

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

1 Answer

I'd say use hash, like this:

(我会说使用哈希,像这样:)

window.onload = function() {
    if(!window.location.hash) {
        window.location = window.location + '#loaded';
        window.location.reload();
    }
}

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