Refresh/Reload web page only once
You should keep a flag in cookie, server session, or local storage. For example:
window.onload = function () {
if (! localStorage.justOnce) {
localStorage.setItem("justOnce", "true");
window.location.reload();
}
}
Reload an HTML page just once using JavaScript
You could use a querystring
at the end of the page url (e.g. ?r), and check for it before redirecting, as if it exists, the redirect is already done.
if(window.location.href.substr(-2) !== "?r") {
window.location = window.location.href + "?r";
}
Disclaimer: I agree with others that you probably have a better solution - and should never need to refresh 'just once'.
Explanation of use
At the bottom of your page, just above the </body>
you should put this:-
<script type="text/javascript">
if(window.location.href.substr(-2) !== "?r") {
window.location = window.location.href + "?r";
}
</script>
That's it.
Related Topics
Whenever I Click Outside the Element It Should Close
How to Set Top and Bottom Margin in Addhtml
How to Clear Location.State in React-Router on Page Reload
How to Reload Datatable by Ajax (Jquery)
Parsing String as Json With Single Quotes
How to Reduce Vendor/Script Bundle.Js in Angular 5
Javascript: How to Read a Hand Held Barcode Scanner Best
Making a JavaScript Function That Finds the First Word in a String/Sentence
Datepicker Onchange Event Not Firing in Jquery
Stop Chrome Back/Forward Two Finger Swipe
How to Reference Static Assets Within Vue JavaScript
Angular 4 | Window.Scrollto(); Is Not Working Properly
How to Get Values of Checkbox in Node Js Using Ejs
How to Post Selected Values Using Ajax
How to Attach Multiple Images in a Embed
Javascript: How to Redirect a Page After Validation
Angular - How to Get Result of a Json Object
How to Get Line Break Within String Interpolation in Angularjs