This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Force iframe Refresh
#1
Hi,

Im using an iframe with some custom javascript to change the source url. I have 1 page set up with page link buttons that all point to the 1 iframe page on the LM, each button has a different additional class that changes the source url. This work fine when hopping between different LM's and websites. But im having trouble accessing different pages on the same LM. I believe the browser is caching the page http://192.168.1.251/scada-vis/#2, when i select a button that changes the url to http://192.168.1.251/scada-vis/#3 it seems the browser is disregarding the /#pagenumber and returns the last cached page of the LM (http://192.168.1.251/scada-vis/#2).

if i move to a different page on the LM and then back to the new URL its fine, it seems to happen only when the iframe has loaded the source and then next url is the same only the /#is different.

Currently my work around is to make separate dedicated iframe pages where this scenario occurs, so an iframe page with a static url http://192.168.1.251/scada-vis/#2, and another with a static url http://192.168.1.251/scada-vis/#3 etc etc

Is there another way to get around this? maybe forcing the iframe to refresh or stop the browser form caching?
Reply
#2
Try changing iframe src twice: first set it to about:blank, then set it to the required URL.
Reply
#3
Did you try to set the refresh interval?
Reply
#4
Hi, Just bringing this up again as i have run into the same problem on another project and would like to avoid creating additional pages/ iframes as i did last time if possible.

I tried setting the URL to blank before changing but i didnt have any luck, i also tried setting the refresh interval but this seemed to refresh to the URL hard set in the iframe property window and not the url from the javascript.

Any other ideas?
Reply
#5
A short delay works for me, try this:
Code:
$(function() {
  function setframe(url) {
    var frame = $('.frame iframe').attr('src', 'about:blank');
    setTimeout(function() {
      frame.attr('src', url);
    }, 10);
  }
  
  $('.btn-1').off('vclick').on('vclick', function() {
    setframe('http://192.168.1.16/scada-vis/#1');
  });
    
  $('.btn-2').off('vclick').on('vclick', function() {
    setframe('http://192.168.1.16/scada-vis/#2');
  });
});
Reply
#6
Thanks, that’s got it working now!
Reply


Forum Jump: