Refresh iFrame (Cache Issue)

后端 未结 5 1023
南旧
南旧 2020-12-08 16:01

We are getting a weird issue on which we are not sure what exactly cause it. Let me elaborate the issue. Suppose, we have two different html pages a.html and b.html. And a l

相关标签:
5条回答
  • 2020-12-08 16:06

    Add this in a.html and b.html

    <head>
        <meta http-Equiv="Cache-Control" Content="no-cache" />
        <meta http-Equiv="Pragma" Content="no-cache" />
        <meta http-Equiv="Expires" Content="0" />
    </head>
    

    To force no cache checks

    0 讨论(0)
  • 2020-12-08 16:07

    For one possible solution to this, pass a "cache parameter" to your calls to a.html and b.html. For example

    HTML

    <input type="button" value="Load a.html" onclick="cacheSafeReload('a.html');">
    

    Javascript

    function cacheSafeReload(urlBase) {
        var cacheParamValue = (new Date()).getTime();
        var url = urlBase + "?cache=" + cacheParamValue;
        reloadFrame(document.getElementById('myFrame'), url);
    }
    
    0 讨论(0)
  • 2020-12-08 16:10

    Homero Barbosa's Solution worked like a charm. In my case, I had a varying number of iframes on the page, so I did the following:

    $('.some_selector').each(function () {
      var $randid = Math.floor(Math.random() * 101);
      $(this).attr({'id': 'goinOnaSafari-' + $randid});
    
      var $frame = document.getElementById('goinOnaSafari-' + $randid);
      $frame.contentWindow.location.href = $frame.src;
    });
    
    0 讨论(0)
  • 2020-12-08 16:13

    Try something like the following:

    <script>
        var frameElement = document.getElementById("frame-id");
        frameElement.contentWindow.location.href = frameElement.src;
    </script>
    

    This will force the iframe to be reloaded even if it was cached by the browser

    0 讨论(0)
  • 2020-12-08 16:14

    If you can add server-side instructions to those HTML files, you could send the appropriate headers to prevent caching:

    Making sure a web page is not cached, across all browsers (I think the consensus is that the 2nd answer is best, not the accepted one)

    Simone's answer already deals with Meta tags.

    A cheap quick trick is to add a random number as a GET parameter:

    page_1.html?time=102398405820
    

    if this changes on every request (e.g. using the current time), reloading wil get forced every time, too.

    0 讨论(0)
提交回复
热议问题