Force page scroll position to top at page refresh in HTML
For a simple plain JavaScript implementation: window.onbeforeunload = function () { window.scrollTo(0, 0); }
For a simple plain JavaScript implementation: window.onbeforeunload = function () { window.scrollTo(0, 0); }
window.onbeforeunload = function(event) { return confirm(“Confirm refresh”); };
Place this in the constructor: if (window.performance) { if (performance.navigation.type == 1) { alert( “This page is reloaded” ); } else { alert( “This page is not reloaded”); } } It will work, please see this example on stackblitz.
You can use pageshow event to handle situation when browser navigates to your page through history traversal: window.addEventListener( “pageshow”, function ( event ) { var historyTraversal = event.persisted || ( typeof window.performance != “undefined” && window.performance.navigation.type === 2 ); if ( historyTraversal ) { // Handle page restore. window.location.reload(); } }); Note that HTTP cache … Read more
Try to use: location.reload(true); When this method receives a true value as argument, it will cause the page to always be reloaded from the server. If it is false or not specified, the browser may reload the page from its cache. More info: The location object
window.location.reload(); in JavaScript <meta http-equiv=”refresh” content=”1″> in HTML (where 1 = 1 second).
⚠️⚠️⚠️ window.performance.navigation.type is deprecated, pls see Илья Зеленько’s answer A better way to know that the page is actually reloaded is to use the navigator object that is supported by most modern browsers. It uses the Navigation Timing API. //check for Navigation Timing API support if (window.performance) { console.info(“window.performance works fine on this browser”); } … Read more