14

I would like to know how to implement a "ctrl+f5" command into my HTML page. I can use javascript or html.

It should be run only when people click in a link.

Thanks, Alex

user2521589
  • 173
  • 1
  • 2
  • 6
  • 1
    possible duplicate of [What is an elegant way to force browsers to reload cached CSS/JS files?](http://stackoverflow.com/questions/118884/what-is-an-elegant-way-to-force-browsers-to-reload-cached-css-js-files) – Diodeus - James MacFarlane Apr 03 '14 at 14:54
  • See https://developer.mozilla.org/en-US/docs/Web/API/Location.reload for a documentation – Stephan Kulla Apr 03 '14 at 17:26
  • See [javascript - Is $window.location.reload(true) the equivalent of CTRL+F5? - Stack Overflow](https://stackoverflow.com/a/45630232/6264260) The main difference: Ctrl-F5 will cause all the attached resources also to reload (scripts, images ...) while the reload(true) will not, the main page (html) will be requested but resources can still be loaded from cache. – Lancer.Yan Dec 12 '19 at 03:50

4 Answers4

27

You should be able to use this javascript to suite your need:

onClick="window.location.reload(true)"

window.location.reload(true) has been deprecated. You can use:

window.location.href = window.location.href

abadillo
  • 195
  • 1
  • 5
individu
  • 359
  • 3
  • 4
  • 5
    Please notice, that this may reload the site from the cache... Use reload(true) if you want a real site reload. – Stephan Kulla Apr 03 '14 at 17:27
  • Also note that this won't reload any external resources like images ecc. – Channel Mar 18 '20 at 09:03
  • if we set the parameter to false... what's the difference? – gumuruh Jul 21 '20 at 07:56
  • What's the definite solution? Many times customer has cached version of a web site. We enabled a web service to detect if there is a new version on Page mount. In case there is a new one, we want to enable a refresh link that will take a new (non cached) version – Jack Casas Jun 02 '22 at 08:57
10

Something like this?

<a href="document.location.reload(true);document.location='/mylink'">Click here to refresh the page</a>
radia
  • 1,456
  • 1
  • 13
  • 18
8

you can create a button for refresh , add the following code into your html page

<a href="JavaScript: location.reload(true);">Refresh page</a>

wissem46
  • 393
  • 3
  • 5
  • 14
0

for automatically refresh you can use a function , like this !

<html>
   <head>
      
      <script type = "text/JavaScript">
         <!--
            function AutoRefresh( t ) {
               setTimeout("location.reload(true);", t);
            }
         //-->
      </script>
      
   </head>


<div id="54666751046"><script type="text/JavaScript" src="https://www.aparat.com/embed/OCINE?data[rnddiv]=54666751046&data[responsive]=yes&muted=true&autoplay=true"></script></div> 
   
   <body onload = "JavaScript:AutoRefresh(5000);">
      <p>This page will refresh every 5 seconds.</p>
   </body>
   
</html>
Blastfurnace
  • 18,411
  • 56
  • 55
  • 70