Συζητήσεις » Αιτήματα Δημιουργίας

Who can help me write a script that makes the page refresh only once?

§
Δημοσιεύτηκε: 29/09/2022

Who can help me write a script that makes the page refresh only once?

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 29/09/2022
Επεξεργάστηκε: 29/09/2022

@'billy Mr', here you go:

(function() {
  var isPageReloaded = localStorage.getItem('__is_page_reloaded') || 0
  if(isPageReloaded < 1) {
    localStorage.setItem('__is_page_reloaded', '1')
    if(location.reload) {
      location.reload()
    } else {
      window.location.href = window.location.href
    }
  }
})()
NotYouΣυντονιστής
§
Δημοσιεύτηκε: 29/09/2022

Here is better version for more browsers:

(function() {
    if(localStorage) {
        var isPageReloaded = localStorage.getItem('__is_page_reloaded') || 0
        if(isPageReloaded < 1) {
            localStorage.setItem('__is_page_reloaded', '1')
            reloadPage()
        }
    } else {
        if(performance.navigation.type !== performance.navigation.TYPE_RELOAD) {
            reloadPage()
        }
    }

    function reloadPage() {
        if(location.reload) {
            location.reload()
        } else {
            window.location.href = window.location.href
        }
    }
})()
NotYouΣυντονιστής
§
Δημοσιεύτηκε: 29/09/2022

By the way, I recommend you to use sessionStorage (instead of localStorage) if you want to check page reloaded or not every time browser is re-opened.

§
Δημοσιεύτηκε: 29/09/2022

NotYou did exactly what I recommended you in the first place.

§
Δημοσιεύτηκε: 29/09/2022

Here is better version for more browsers:

(function() {
    if(localStorage) {
        var isPageReloaded = localStorage.getItem('__is_page_reloaded') || 0
        if(isPageReloaded < 1) {
            localStorage.setItem('__is_page_reloaded', '1')
            reloadPage()
        }
    } else {
        if(performance.navigation.type !== performance.navigation.TYPE_RELOAD) {
            reloadPage()
        }
    }

    function reloadPage() {
        if(location.reload) {
            location.reload()
        } else {
            window.location.href = window.location.href
        }
    }
})()

My Bro. Thank you very much for your time to help me. You are such a great guy.

Since I have dozens of tabs open at the same time, it seems that this script doesn't refresh asynchronously.
The function I hope to achieve is that a page is refreshed and loaded again after 10 seconds.

NotYouΣυντονιστής
§
Δημοσιεύτηκε: 03/10/2022

@'billy Mr' that seems to be DDOS-like script... Sorry man, can't help you for that one, is seem to be malicious thing for me.

§
Δημοσιεύτηκε: 06/10/2022

@'billy Mr' that seems to be DDOS-like script...Sorry man,can't help you for that one,is seem to be malicious thing for me.

Anyway, I'm always grateful to you.

Δημοσίευση απάντησης

Συνδεθείτε για να δημοσιεύσετε μια απάντηση.

长期地址
遇到问题?请前往 GitHub 提 Issues。