How to refresh an IFrame using Javascript?












97















I have a webpage with an IFrame and a Button, once the button is pressed I need the IFrame to be refreshed. Is this possible, if so how? I searched and could not find any answers.










share|improve this question


















  • 1





    possible duplicate of What's the best way to reload an iframe using JavaScript?

    – j0k
    Jan 27 '15 at 16:33
















97















I have a webpage with an IFrame and a Button, once the button is pressed I need the IFrame to be refreshed. Is this possible, if so how? I searched and could not find any answers.










share|improve this question


















  • 1





    possible duplicate of What's the best way to reload an iframe using JavaScript?

    – j0k
    Jan 27 '15 at 16:33














97












97








97


26






I have a webpage with an IFrame and a Button, once the button is pressed I need the IFrame to be refreshed. Is this possible, if so how? I searched and could not find any answers.










share|improve this question














I have a webpage with an IFrame and a Button, once the button is pressed I need the IFrame to be refreshed. Is this possible, if so how? I searched and could not find any answers.







javascript iframe






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 14 '10 at 14:42









RolandRoland

12.2k59155215




12.2k59155215








  • 1





    possible duplicate of What's the best way to reload an iframe using JavaScript?

    – j0k
    Jan 27 '15 at 16:33














  • 1





    possible duplicate of What's the best way to reload an iframe using JavaScript?

    – j0k
    Jan 27 '15 at 16:33








1




1





possible duplicate of What's the best way to reload an iframe using JavaScript?

– j0k
Jan 27 '15 at 16:33





possible duplicate of What's the best way to reload an iframe using JavaScript?

– j0k
Jan 27 '15 at 16:33












13 Answers
13






active

oldest

votes


















116














var iframe = document.getElementById('youriframe');
iframe.src = iframe.src;





share|improve this answer



















  • 6





    Does not work in Chrome. At least not in Chrome 19...

    – Tarlog
    Jun 18 '12 at 10:08






  • 2





    It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

    – Paul A Jungwirth
    Mar 13 '13 at 17:13






  • 2





    FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

    – Robert Altman
    Apr 10 '13 at 16:58






  • 1





    Did not work for chrome 27!

    – user2019515
    May 27 '13 at 6:40






  • 7





    var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

    – lyfing
    Jan 27 '15 at 8:28



















96














This should help:



document.getElementById('FrameID').contentWindow.location.reload(true);


EDIT: Fixed the object name as per @Joro's comment.






share|improve this answer





















  • 3





    This is not working in IE9. You should use contentWindow instead contentDocument.

    – gotqn
    Aug 9 '12 at 11:24






  • 1





    Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

    – racl101
    Aug 19 '14 at 21:54








  • 7





    This does not work with iframes with different origins (protocol, hostname or port).

    – michelpm
    Jul 24 '15 at 1:58











  • Thank You,Its working for me.

    – SwR
    Apr 25 '16 at 9:47



















11














provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:



iframe.contentWindow.location.reload();





share|improve this answer


























  • This does not work for cross-origin iframe.

    – Franklin Yu
    Nov 16 '18 at 15:20



















6














Works for IE, Mozzila, Chrome



document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);





share|improve this answer



















  • 1





    Thank you!!! That working in Chrome 60.0.3112.101

    – Dennis Y. Parygin
    Aug 22 '17 at 11:26



















3














You can use this simple method



function reloadFrame(iFrame) {

iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

}





share|improve this answer































    2














    Got this from here



    var f = document.getElementById('iframe1');
    f.src = f.src;





    share|improve this answer
























    • If into iFrame change the page, this method lost the navigation

      – Eduardo Cuomo
      Jun 26 '13 at 12:16



















    2














    2017:



    If it in on same domain just :



    iframe.contentWindow.location.reload();


    will work.






    share|improve this answer































      1














      Here is the HTML snippet:



      <td><iframe name="idFrame" id="idFrame" src="chat.txt" width="468" height="300"></iframe></td>


      And my Javascript code:



      window.onload = function(){
      setInterval(function(){
      parent.frames['idFrame'].location.href = "chat.txt";
      },1000);}





      share|improve this answer































        1














        Resetting the src attribute directly:



        iframe.src = iframe.src;


        Resetting the src with a time stamp for cache busting:



        iframe.src =  iframe.src.split("?")[0] + "?_=" + new Date().getTime();


        Clearing the src when query strings option is not possible (Data URI):



        var wasSrc = iframe.src

        iframe.onload = function() {
        iframe.onload = undefined;
        iframe.src = wasSrc;
        }





        share|improve this answer

































          1














          If you use hash paths (like mywebsite.com/#/my/url) which might not refresh frames on switching hash:



          <script>
          window.onhashchange = function () {
          window.setTimeout(function () {
          let frame = document.getElementById('myFrame');
          if (frame !== null) {frame.replaceWith(frame);}
          }, 1000);
          }
          </script>


          Unfortunately, if you don't use the timeout JS may try to replace the frame before the page has finished loading the content (thus loading the old content). I'm not sure of the workaround yet.






          share|improve this answer

































            0














            If you have Multiple iFrames inside the page, then this script might be useful. I am asuming there is a specific value in the iFrame source which can be used to find the specific iFrame.



            var iframes = document.getElementsByTagName('iframe');
            var yourIframe = null
            for(var i=0; i < iframes.length ;i++){
            var source = iframes[i].attributes.src.nodeValue;
            if(source.indexOf('/yourSorce') > -1){
            yourIframe = iframes[i];
            }
            }
            var iSource = yourIframe.attributes.src.nodeValue;
            yourIframe.src = iSource;


            Replace "/yourSource" with value you need.






            share|improve this answer































              0














              If your iframe's URL does not change, you can just recreate it.



              If your iframe is not from the same origin (protocol scheme, hostname and port), you will not be able to know the current URL in the iframe, so you will need a script in the iframe document to exchange messages with its parent window (the page's window).



              In the iframe document:



              window.addEventListener('change', function(e) {
              if (e.data === 'Please reload yourself') {
              var skipCache = true; // true === Shift+F5
              window.location.reload(skipCache);
              }
              }


              In your page:



              var iframe = document.getElementById('my-iframe');
              var targetOrigin = iframe.src; // Use '*' if you don't care
              iframe.postMessage('Please reload yourself', targetOrigin);





              share|improve this answer































                -1














                You can use this:



                Js:



                function refreshFrame(){
                $('#myFrame').attr('src', "http://blablab.com?v=");
                }


                Html:



                `<iframe id="myFrame" src=""></iframe>`


                JS Fiddle : https://jsfiddle.net/wpb20vzx/






                share|improve this answer





















                • 1





                  The question has nothing to do with the popular JavaScript library called jQuery.

                  – John Weisz
                  May 19 '15 at 7:59













                • What would Math.round() do? It looks totally useless here.

                  – Davide R.
                  Jun 11 '15 at 10:44











                • Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                  – Ferhat KOÇER
                  Jun 12 '15 at 7:59








                • 4





                  I think you meant Math.random() lol

                  – michelpm
                  Jul 24 '15 at 1:51










                protected by Community Aug 13 '15 at 16:01



                Thank you for your interest in this question.
                Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                Would you like to answer one of these unanswered questions instead?














                13 Answers
                13






                active

                oldest

                votes








                13 Answers
                13






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                116














                var iframe = document.getElementById('youriframe');
                iframe.src = iframe.src;





                share|improve this answer



















                • 6





                  Does not work in Chrome. At least not in Chrome 19...

                  – Tarlog
                  Jun 18 '12 at 10:08






                • 2





                  It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                  – Paul A Jungwirth
                  Mar 13 '13 at 17:13






                • 2





                  FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                  – Robert Altman
                  Apr 10 '13 at 16:58






                • 1





                  Did not work for chrome 27!

                  – user2019515
                  May 27 '13 at 6:40






                • 7





                  var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                  – lyfing
                  Jan 27 '15 at 8:28
















                116














                var iframe = document.getElementById('youriframe');
                iframe.src = iframe.src;





                share|improve this answer



















                • 6





                  Does not work in Chrome. At least not in Chrome 19...

                  – Tarlog
                  Jun 18 '12 at 10:08






                • 2





                  It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                  – Paul A Jungwirth
                  Mar 13 '13 at 17:13






                • 2





                  FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                  – Robert Altman
                  Apr 10 '13 at 16:58






                • 1





                  Did not work for chrome 27!

                  – user2019515
                  May 27 '13 at 6:40






                • 7





                  var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                  – lyfing
                  Jan 27 '15 at 8:28














                116












                116








                116







                var iframe = document.getElementById('youriframe');
                iframe.src = iframe.src;





                share|improve this answer













                var iframe = document.getElementById('youriframe');
                iframe.src = iframe.src;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 14 '10 at 14:45









                kjagiellokjagiello

                6,33722343




                6,33722343








                • 6





                  Does not work in Chrome. At least not in Chrome 19...

                  – Tarlog
                  Jun 18 '12 at 10:08






                • 2





                  It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                  – Paul A Jungwirth
                  Mar 13 '13 at 17:13






                • 2





                  FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                  – Robert Altman
                  Apr 10 '13 at 16:58






                • 1





                  Did not work for chrome 27!

                  – user2019515
                  May 27 '13 at 6:40






                • 7





                  var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                  – lyfing
                  Jan 27 '15 at 8:28














                • 6





                  Does not work in Chrome. At least not in Chrome 19...

                  – Tarlog
                  Jun 18 '12 at 10:08






                • 2





                  It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                  – Paul A Jungwirth
                  Mar 13 '13 at 17:13






                • 2





                  FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                  – Robert Altman
                  Apr 10 '13 at 16:58






                • 1





                  Did not work for chrome 27!

                  – user2019515
                  May 27 '13 at 6:40






                • 7





                  var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                  – lyfing
                  Jan 27 '15 at 8:28








                6




                6





                Does not work in Chrome. At least not in Chrome 19...

                – Tarlog
                Jun 18 '12 at 10:08





                Does not work in Chrome. At least not in Chrome 19...

                – Tarlog
                Jun 18 '12 at 10:08




                2




                2





                It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                – Paul A Jungwirth
                Mar 13 '13 at 17:13





                It works for me in this version of Chrome: Version 24.0.1312.56 Ubuntu 12.04 (24.0.1312.56-0ubuntu0.12.04.1)

                – Paul A Jungwirth
                Mar 13 '13 at 17:13




                2




                2





                FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                – Robert Altman
                Apr 10 '13 at 16:58





                FYI - There is currently (as of January 2013) a Chromium project bug (code.google.com/p/chromium/issues/detail?id=172859) which causes iframe updates to add to document history.

                – Robert Altman
                Apr 10 '13 at 16:58




                1




                1





                Did not work for chrome 27!

                – user2019515
                May 27 '13 at 6:40





                Did not work for chrome 27!

                – user2019515
                May 27 '13 at 6:40




                7




                7





                var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                – lyfing
                Jan 27 '15 at 8:28





                var tmp_src = iframe.src; iframe.src = ''; iframe.src = tmp_src;

                – lyfing
                Jan 27 '15 at 8:28













                96














                This should help:



                document.getElementById('FrameID').contentWindow.location.reload(true);


                EDIT: Fixed the object name as per @Joro's comment.






                share|improve this answer





















                • 3





                  This is not working in IE9. You should use contentWindow instead contentDocument.

                  – gotqn
                  Aug 9 '12 at 11:24






                • 1





                  Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                  – racl101
                  Aug 19 '14 at 21:54








                • 7





                  This does not work with iframes with different origins (protocol, hostname or port).

                  – michelpm
                  Jul 24 '15 at 1:58











                • Thank You,Its working for me.

                  – SwR
                  Apr 25 '16 at 9:47
















                96














                This should help:



                document.getElementById('FrameID').contentWindow.location.reload(true);


                EDIT: Fixed the object name as per @Joro's comment.






                share|improve this answer





















                • 3





                  This is not working in IE9. You should use contentWindow instead contentDocument.

                  – gotqn
                  Aug 9 '12 at 11:24






                • 1





                  Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                  – racl101
                  Aug 19 '14 at 21:54








                • 7





                  This does not work with iframes with different origins (protocol, hostname or port).

                  – michelpm
                  Jul 24 '15 at 1:58











                • Thank You,Its working for me.

                  – SwR
                  Apr 25 '16 at 9:47














                96












                96








                96







                This should help:



                document.getElementById('FrameID').contentWindow.location.reload(true);


                EDIT: Fixed the object name as per @Joro's comment.






                share|improve this answer















                This should help:



                document.getElementById('FrameID').contentWindow.location.reload(true);


                EDIT: Fixed the object name as per @Joro's comment.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Aug 9 '12 at 11:47

























                answered Jan 14 '10 at 14:47









                nfechnernfechner

                15k53960




                15k53960








                • 3





                  This is not working in IE9. You should use contentWindow instead contentDocument.

                  – gotqn
                  Aug 9 '12 at 11:24






                • 1





                  Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                  – racl101
                  Aug 19 '14 at 21:54








                • 7





                  This does not work with iframes with different origins (protocol, hostname or port).

                  – michelpm
                  Jul 24 '15 at 1:58











                • Thank You,Its working for me.

                  – SwR
                  Apr 25 '16 at 9:47














                • 3





                  This is not working in IE9. You should use contentWindow instead contentDocument.

                  – gotqn
                  Aug 9 '12 at 11:24






                • 1





                  Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                  – racl101
                  Aug 19 '14 at 21:54








                • 7





                  This does not work with iframes with different origins (protocol, hostname or port).

                  – michelpm
                  Jul 24 '15 at 1:58











                • Thank You,Its working for me.

                  – SwR
                  Apr 25 '16 at 9:47








                3




                3





                This is not working in IE9. You should use contentWindow instead contentDocument.

                – gotqn
                Aug 9 '12 at 11:24





                This is not working in IE9. You should use contentWindow instead contentDocument.

                – gotqn
                Aug 9 '12 at 11:24




                1




                1





                Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                – racl101
                Aug 19 '14 at 21:54







                Thanks for the answer. Additionally, If you must positively cause a refresh to another page to another within the iframe then instead of reload(true) you would use this: document.getElementById('FrameID').contentWindow.location.replace(new_url);

                – racl101
                Aug 19 '14 at 21:54






                7




                7





                This does not work with iframes with different origins (protocol, hostname or port).

                – michelpm
                Jul 24 '15 at 1:58





                This does not work with iframes with different origins (protocol, hostname or port).

                – michelpm
                Jul 24 '15 at 1:58













                Thank You,Its working for me.

                – SwR
                Apr 25 '16 at 9:47





                Thank You,Its working for me.

                – SwR
                Apr 25 '16 at 9:47











                11














                provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:



                iframe.contentWindow.location.reload();





                share|improve this answer


























                • This does not work for cross-origin iframe.

                  – Franklin Yu
                  Nov 16 '18 at 15:20
















                11














                provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:



                iframe.contentWindow.location.reload();





                share|improve this answer


























                • This does not work for cross-origin iframe.

                  – Franklin Yu
                  Nov 16 '18 at 15:20














                11












                11








                11







                provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:



                iframe.contentWindow.location.reload();





                share|improve this answer















                provided the iframe is loaded from the same domain, you can do this, which makes a little more sense:



                iframe.contentWindow.location.reload();






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '18 at 8:02









                Mohammad

                15.7k123562




                15.7k123562










                answered Jan 14 '10 at 14:50









                Horia DragomirHoria Dragomir

                2,5321821




                2,5321821













                • This does not work for cross-origin iframe.

                  – Franklin Yu
                  Nov 16 '18 at 15:20



















                • This does not work for cross-origin iframe.

                  – Franklin Yu
                  Nov 16 '18 at 15:20

















                This does not work for cross-origin iframe.

                – Franklin Yu
                Nov 16 '18 at 15:20





                This does not work for cross-origin iframe.

                – Franklin Yu
                Nov 16 '18 at 15:20











                6














                Works for IE, Mozzila, Chrome



                document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);





                share|improve this answer



















                • 1





                  Thank you!!! That working in Chrome 60.0.3112.101

                  – Dennis Y. Parygin
                  Aug 22 '17 at 11:26
















                6














                Works for IE, Mozzila, Chrome



                document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);





                share|improve this answer



















                • 1





                  Thank you!!! That working in Chrome 60.0.3112.101

                  – Dennis Y. Parygin
                  Aug 22 '17 at 11:26














                6












                6








                6







                Works for IE, Mozzila, Chrome



                document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);





                share|improve this answer













                Works for IE, Mozzila, Chrome



                document.getElementById('YOUR IFRAME').contentDocument.location.reload(true);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 13 '14 at 10:40









                Marek PavelekMarek Pavelek

                758812




                758812








                • 1





                  Thank you!!! That working in Chrome 60.0.3112.101

                  – Dennis Y. Parygin
                  Aug 22 '17 at 11:26














                • 1





                  Thank you!!! That working in Chrome 60.0.3112.101

                  – Dennis Y. Parygin
                  Aug 22 '17 at 11:26








                1




                1





                Thank you!!! That working in Chrome 60.0.3112.101

                – Dennis Y. Parygin
                Aug 22 '17 at 11:26





                Thank you!!! That working in Chrome 60.0.3112.101

                – Dennis Y. Parygin
                Aug 22 '17 at 11:26











                3














                You can use this simple method



                function reloadFrame(iFrame) {

                iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

                }





                share|improve this answer




























                  3














                  You can use this simple method



                  function reloadFrame(iFrame) {

                  iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

                  }





                  share|improve this answer


























                    3












                    3








                    3







                    You can use this simple method



                    function reloadFrame(iFrame) {

                    iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

                    }





                    share|improve this answer













                    You can use this simple method



                    function reloadFrame(iFrame) {

                    iFrame.parentNode.replaceChild(iFrame.cloneNode(), iFrame);

                    }






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 14 '16 at 15:42









                    Vasile Alexandru PesteVasile Alexandru Peste

                    1169




                    1169























                        2














                        Got this from here



                        var f = document.getElementById('iframe1');
                        f.src = f.src;





                        share|improve this answer
























                        • If into iFrame change the page, this method lost the navigation

                          – Eduardo Cuomo
                          Jun 26 '13 at 12:16
















                        2














                        Got this from here



                        var f = document.getElementById('iframe1');
                        f.src = f.src;





                        share|improve this answer
























                        • If into iFrame change the page, this method lost the navigation

                          – Eduardo Cuomo
                          Jun 26 '13 at 12:16














                        2












                        2








                        2







                        Got this from here



                        var f = document.getElementById('iframe1');
                        f.src = f.src;





                        share|improve this answer













                        Got this from here



                        var f = document.getElementById('iframe1');
                        f.src = f.src;






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jan 14 '10 at 14:47









                        AmarghoshAmarghosh

                        48.8k1078112




                        48.8k1078112













                        • If into iFrame change the page, this method lost the navigation

                          – Eduardo Cuomo
                          Jun 26 '13 at 12:16



















                        • If into iFrame change the page, this method lost the navigation

                          – Eduardo Cuomo
                          Jun 26 '13 at 12:16

















                        If into iFrame change the page, this method lost the navigation

                        – Eduardo Cuomo
                        Jun 26 '13 at 12:16





                        If into iFrame change the page, this method lost the navigation

                        – Eduardo Cuomo
                        Jun 26 '13 at 12:16











                        2














                        2017:



                        If it in on same domain just :



                        iframe.contentWindow.location.reload();


                        will work.






                        share|improve this answer




























                          2














                          2017:



                          If it in on same domain just :



                          iframe.contentWindow.location.reload();


                          will work.






                          share|improve this answer


























                            2












                            2








                            2







                            2017:



                            If it in on same domain just :



                            iframe.contentWindow.location.reload();


                            will work.






                            share|improve this answer













                            2017:



                            If it in on same domain just :



                            iframe.contentWindow.location.reload();


                            will work.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 20 '17 at 15:11









                            pery mimonpery mimon

                            2,26222030




                            2,26222030























                                1














                                Here is the HTML snippet:



                                <td><iframe name="idFrame" id="idFrame" src="chat.txt" width="468" height="300"></iframe></td>


                                And my Javascript code:



                                window.onload = function(){
                                setInterval(function(){
                                parent.frames['idFrame'].location.href = "chat.txt";
                                },1000);}





                                share|improve this answer




























                                  1














                                  Here is the HTML snippet:



                                  <td><iframe name="idFrame" id="idFrame" src="chat.txt" width="468" height="300"></iframe></td>


                                  And my Javascript code:



                                  window.onload = function(){
                                  setInterval(function(){
                                  parent.frames['idFrame'].location.href = "chat.txt";
                                  },1000);}





                                  share|improve this answer


























                                    1












                                    1








                                    1







                                    Here is the HTML snippet:



                                    <td><iframe name="idFrame" id="idFrame" src="chat.txt" width="468" height="300"></iframe></td>


                                    And my Javascript code:



                                    window.onload = function(){
                                    setInterval(function(){
                                    parent.frames['idFrame'].location.href = "chat.txt";
                                    },1000);}





                                    share|improve this answer













                                    Here is the HTML snippet:



                                    <td><iframe name="idFrame" id="idFrame" src="chat.txt" width="468" height="300"></iframe></td>


                                    And my Javascript code:



                                    window.onload = function(){
                                    setInterval(function(){
                                    parent.frames['idFrame'].location.href = "chat.txt";
                                    },1000);}






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Dec 4 '13 at 13:14









                                    TonyTony

                                    714




                                    714























                                        1














                                        Resetting the src attribute directly:



                                        iframe.src = iframe.src;


                                        Resetting the src with a time stamp for cache busting:



                                        iframe.src =  iframe.src.split("?")[0] + "?_=" + new Date().getTime();


                                        Clearing the src when query strings option is not possible (Data URI):



                                        var wasSrc = iframe.src

                                        iframe.onload = function() {
                                        iframe.onload = undefined;
                                        iframe.src = wasSrc;
                                        }





                                        share|improve this answer






























                                          1














                                          Resetting the src attribute directly:



                                          iframe.src = iframe.src;


                                          Resetting the src with a time stamp for cache busting:



                                          iframe.src =  iframe.src.split("?")[0] + "?_=" + new Date().getTime();


                                          Clearing the src when query strings option is not possible (Data URI):



                                          var wasSrc = iframe.src

                                          iframe.onload = function() {
                                          iframe.onload = undefined;
                                          iframe.src = wasSrc;
                                          }





                                          share|improve this answer




























                                            1












                                            1








                                            1







                                            Resetting the src attribute directly:



                                            iframe.src = iframe.src;


                                            Resetting the src with a time stamp for cache busting:



                                            iframe.src =  iframe.src.split("?")[0] + "?_=" + new Date().getTime();


                                            Clearing the src when query strings option is not possible (Data URI):



                                            var wasSrc = iframe.src

                                            iframe.onload = function() {
                                            iframe.onload = undefined;
                                            iframe.src = wasSrc;
                                            }





                                            share|improve this answer















                                            Resetting the src attribute directly:



                                            iframe.src = iframe.src;


                                            Resetting the src with a time stamp for cache busting:



                                            iframe.src =  iframe.src.split("?")[0] + "?_=" + new Date().getTime();


                                            Clearing the src when query strings option is not possible (Data URI):



                                            var wasSrc = iframe.src

                                            iframe.onload = function() {
                                            iframe.onload = undefined;
                                            iframe.src = wasSrc;
                                            }






                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited Oct 3 '16 at 20:49

























                                            answered Oct 3 '16 at 20:33









                                            lcharbonlcharbon

                                            5771511




                                            5771511























                                                1














                                                If you use hash paths (like mywebsite.com/#/my/url) which might not refresh frames on switching hash:



                                                <script>
                                                window.onhashchange = function () {
                                                window.setTimeout(function () {
                                                let frame = document.getElementById('myFrame');
                                                if (frame !== null) {frame.replaceWith(frame);}
                                                }, 1000);
                                                }
                                                </script>


                                                Unfortunately, if you don't use the timeout JS may try to replace the frame before the page has finished loading the content (thus loading the old content). I'm not sure of the workaround yet.






                                                share|improve this answer






























                                                  1














                                                  If you use hash paths (like mywebsite.com/#/my/url) which might not refresh frames on switching hash:



                                                  <script>
                                                  window.onhashchange = function () {
                                                  window.setTimeout(function () {
                                                  let frame = document.getElementById('myFrame');
                                                  if (frame !== null) {frame.replaceWith(frame);}
                                                  }, 1000);
                                                  }
                                                  </script>


                                                  Unfortunately, if you don't use the timeout JS may try to replace the frame before the page has finished loading the content (thus loading the old content). I'm not sure of the workaround yet.






                                                  share|improve this answer




























                                                    1












                                                    1








                                                    1







                                                    If you use hash paths (like mywebsite.com/#/my/url) which might not refresh frames on switching hash:



                                                    <script>
                                                    window.onhashchange = function () {
                                                    window.setTimeout(function () {
                                                    let frame = document.getElementById('myFrame');
                                                    if (frame !== null) {frame.replaceWith(frame);}
                                                    }, 1000);
                                                    }
                                                    </script>


                                                    Unfortunately, if you don't use the timeout JS may try to replace the frame before the page has finished loading the content (thus loading the old content). I'm not sure of the workaround yet.






                                                    share|improve this answer















                                                    If you use hash paths (like mywebsite.com/#/my/url) which might not refresh frames on switching hash:



                                                    <script>
                                                    window.onhashchange = function () {
                                                    window.setTimeout(function () {
                                                    let frame = document.getElementById('myFrame');
                                                    if (frame !== null) {frame.replaceWith(frame);}
                                                    }, 1000);
                                                    }
                                                    </script>


                                                    Unfortunately, if you don't use the timeout JS may try to replace the frame before the page has finished loading the content (thus loading the old content). I'm not sure of the workaround yet.







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Jun 20 '18 at 23:48

























                                                    answered Jun 20 '18 at 22:39









                                                    NotoriousPyroNotoriousPyro

                                                    308111




                                                    308111























                                                        0














                                                        If you have Multiple iFrames inside the page, then this script might be useful. I am asuming there is a specific value in the iFrame source which can be used to find the specific iFrame.



                                                        var iframes = document.getElementsByTagName('iframe');
                                                        var yourIframe = null
                                                        for(var i=0; i < iframes.length ;i++){
                                                        var source = iframes[i].attributes.src.nodeValue;
                                                        if(source.indexOf('/yourSorce') > -1){
                                                        yourIframe = iframes[i];
                                                        }
                                                        }
                                                        var iSource = yourIframe.attributes.src.nodeValue;
                                                        yourIframe.src = iSource;


                                                        Replace "/yourSource" with value you need.






                                                        share|improve this answer




























                                                          0














                                                          If you have Multiple iFrames inside the page, then this script might be useful. I am asuming there is a specific value in the iFrame source which can be used to find the specific iFrame.



                                                          var iframes = document.getElementsByTagName('iframe');
                                                          var yourIframe = null
                                                          for(var i=0; i < iframes.length ;i++){
                                                          var source = iframes[i].attributes.src.nodeValue;
                                                          if(source.indexOf('/yourSorce') > -1){
                                                          yourIframe = iframes[i];
                                                          }
                                                          }
                                                          var iSource = yourIframe.attributes.src.nodeValue;
                                                          yourIframe.src = iSource;


                                                          Replace "/yourSource" with value you need.






                                                          share|improve this answer


























                                                            0












                                                            0








                                                            0







                                                            If you have Multiple iFrames inside the page, then this script might be useful. I am asuming there is a specific value in the iFrame source which can be used to find the specific iFrame.



                                                            var iframes = document.getElementsByTagName('iframe');
                                                            var yourIframe = null
                                                            for(var i=0; i < iframes.length ;i++){
                                                            var source = iframes[i].attributes.src.nodeValue;
                                                            if(source.indexOf('/yourSorce') > -1){
                                                            yourIframe = iframes[i];
                                                            }
                                                            }
                                                            var iSource = yourIframe.attributes.src.nodeValue;
                                                            yourIframe.src = iSource;


                                                            Replace "/yourSource" with value you need.






                                                            share|improve this answer













                                                            If you have Multiple iFrames inside the page, then this script might be useful. I am asuming there is a specific value in the iFrame source which can be used to find the specific iFrame.



                                                            var iframes = document.getElementsByTagName('iframe');
                                                            var yourIframe = null
                                                            for(var i=0; i < iframes.length ;i++){
                                                            var source = iframes[i].attributes.src.nodeValue;
                                                            if(source.indexOf('/yourSorce') > -1){
                                                            yourIframe = iframes[i];
                                                            }
                                                            }
                                                            var iSource = yourIframe.attributes.src.nodeValue;
                                                            yourIframe.src = iSource;


                                                            Replace "/yourSource" with value you need.







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Dec 11 '13 at 11:15









                                                            sarvesh singhsarvesh singh

                                                            28934




                                                            28934























                                                                0














                                                                If your iframe's URL does not change, you can just recreate it.



                                                                If your iframe is not from the same origin (protocol scheme, hostname and port), you will not be able to know the current URL in the iframe, so you will need a script in the iframe document to exchange messages with its parent window (the page's window).



                                                                In the iframe document:



                                                                window.addEventListener('change', function(e) {
                                                                if (e.data === 'Please reload yourself') {
                                                                var skipCache = true; // true === Shift+F5
                                                                window.location.reload(skipCache);
                                                                }
                                                                }


                                                                In your page:



                                                                var iframe = document.getElementById('my-iframe');
                                                                var targetOrigin = iframe.src; // Use '*' if you don't care
                                                                iframe.postMessage('Please reload yourself', targetOrigin);





                                                                share|improve this answer




























                                                                  0














                                                                  If your iframe's URL does not change, you can just recreate it.



                                                                  If your iframe is not from the same origin (protocol scheme, hostname and port), you will not be able to know the current URL in the iframe, so you will need a script in the iframe document to exchange messages with its parent window (the page's window).



                                                                  In the iframe document:



                                                                  window.addEventListener('change', function(e) {
                                                                  if (e.data === 'Please reload yourself') {
                                                                  var skipCache = true; // true === Shift+F5
                                                                  window.location.reload(skipCache);
                                                                  }
                                                                  }


                                                                  In your page:



                                                                  var iframe = document.getElementById('my-iframe');
                                                                  var targetOrigin = iframe.src; // Use '*' if you don't care
                                                                  iframe.postMessage('Please reload yourself', targetOrigin);





                                                                  share|improve this answer


























                                                                    0












                                                                    0








                                                                    0







                                                                    If your iframe's URL does not change, you can just recreate it.



                                                                    If your iframe is not from the same origin (protocol scheme, hostname and port), you will not be able to know the current URL in the iframe, so you will need a script in the iframe document to exchange messages with its parent window (the page's window).



                                                                    In the iframe document:



                                                                    window.addEventListener('change', function(e) {
                                                                    if (e.data === 'Please reload yourself') {
                                                                    var skipCache = true; // true === Shift+F5
                                                                    window.location.reload(skipCache);
                                                                    }
                                                                    }


                                                                    In your page:



                                                                    var iframe = document.getElementById('my-iframe');
                                                                    var targetOrigin = iframe.src; // Use '*' if you don't care
                                                                    iframe.postMessage('Please reload yourself', targetOrigin);





                                                                    share|improve this answer













                                                                    If your iframe's URL does not change, you can just recreate it.



                                                                    If your iframe is not from the same origin (protocol scheme, hostname and port), you will not be able to know the current URL in the iframe, so you will need a script in the iframe document to exchange messages with its parent window (the page's window).



                                                                    In the iframe document:



                                                                    window.addEventListener('change', function(e) {
                                                                    if (e.data === 'Please reload yourself') {
                                                                    var skipCache = true; // true === Shift+F5
                                                                    window.location.reload(skipCache);
                                                                    }
                                                                    }


                                                                    In your page:



                                                                    var iframe = document.getElementById('my-iframe');
                                                                    var targetOrigin = iframe.src; // Use '*' if you don't care
                                                                    iframe.postMessage('Please reload yourself', targetOrigin);






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Jul 24 '15 at 2:37









                                                                    michelpmmichelpm

                                                                    1,07521431




                                                                    1,07521431























                                                                        -1














                                                                        You can use this:



                                                                        Js:



                                                                        function refreshFrame(){
                                                                        $('#myFrame').attr('src', "http://blablab.com?v=");
                                                                        }


                                                                        Html:



                                                                        `<iframe id="myFrame" src=""></iframe>`


                                                                        JS Fiddle : https://jsfiddle.net/wpb20vzx/






                                                                        share|improve this answer





















                                                                        • 1





                                                                          The question has nothing to do with the popular JavaScript library called jQuery.

                                                                          – John Weisz
                                                                          May 19 '15 at 7:59













                                                                        • What would Math.round() do? It looks totally useless here.

                                                                          – Davide R.
                                                                          Jun 11 '15 at 10:44











                                                                        • Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                          – Ferhat KOÇER
                                                                          Jun 12 '15 at 7:59








                                                                        • 4





                                                                          I think you meant Math.random() lol

                                                                          – michelpm
                                                                          Jul 24 '15 at 1:51
















                                                                        -1














                                                                        You can use this:



                                                                        Js:



                                                                        function refreshFrame(){
                                                                        $('#myFrame').attr('src', "http://blablab.com?v=");
                                                                        }


                                                                        Html:



                                                                        `<iframe id="myFrame" src=""></iframe>`


                                                                        JS Fiddle : https://jsfiddle.net/wpb20vzx/






                                                                        share|improve this answer





















                                                                        • 1





                                                                          The question has nothing to do with the popular JavaScript library called jQuery.

                                                                          – John Weisz
                                                                          May 19 '15 at 7:59













                                                                        • What would Math.round() do? It looks totally useless here.

                                                                          – Davide R.
                                                                          Jun 11 '15 at 10:44











                                                                        • Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                          – Ferhat KOÇER
                                                                          Jun 12 '15 at 7:59








                                                                        • 4





                                                                          I think you meant Math.random() lol

                                                                          – michelpm
                                                                          Jul 24 '15 at 1:51














                                                                        -1












                                                                        -1








                                                                        -1







                                                                        You can use this:



                                                                        Js:



                                                                        function refreshFrame(){
                                                                        $('#myFrame').attr('src', "http://blablab.com?v=");
                                                                        }


                                                                        Html:



                                                                        `<iframe id="myFrame" src=""></iframe>`


                                                                        JS Fiddle : https://jsfiddle.net/wpb20vzx/






                                                                        share|improve this answer















                                                                        You can use this:



                                                                        Js:



                                                                        function refreshFrame(){
                                                                        $('#myFrame').attr('src', "http://blablab.com?v=");
                                                                        }


                                                                        Html:



                                                                        `<iframe id="myFrame" src=""></iframe>`


                                                                        JS Fiddle : https://jsfiddle.net/wpb20vzx/







                                                                        share|improve this answer














                                                                        share|improve this answer



                                                                        share|improve this answer








                                                                        edited Aug 21 '15 at 11:00

























                                                                        answered May 19 '15 at 7:45









                                                                        Ferhat KOÇERFerhat KOÇER

                                                                        1,6841314




                                                                        1,6841314








                                                                        • 1





                                                                          The question has nothing to do with the popular JavaScript library called jQuery.

                                                                          – John Weisz
                                                                          May 19 '15 at 7:59













                                                                        • What would Math.round() do? It looks totally useless here.

                                                                          – Davide R.
                                                                          Jun 11 '15 at 10:44











                                                                        • Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                          – Ferhat KOÇER
                                                                          Jun 12 '15 at 7:59








                                                                        • 4





                                                                          I think you meant Math.random() lol

                                                                          – michelpm
                                                                          Jul 24 '15 at 1:51














                                                                        • 1





                                                                          The question has nothing to do with the popular JavaScript library called jQuery.

                                                                          – John Weisz
                                                                          May 19 '15 at 7:59













                                                                        • What would Math.round() do? It looks totally useless here.

                                                                          – Davide R.
                                                                          Jun 11 '15 at 10:44











                                                                        • Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                          – Ferhat KOÇER
                                                                          Jun 12 '15 at 7:59








                                                                        • 4





                                                                          I think you meant Math.random() lol

                                                                          – michelpm
                                                                          Jul 24 '15 at 1:51








                                                                        1




                                                                        1





                                                                        The question has nothing to do with the popular JavaScript library called jQuery.

                                                                        – John Weisz
                                                                        May 19 '15 at 7:59







                                                                        The question has nothing to do with the popular JavaScript library called jQuery.

                                                                        – John Weisz
                                                                        May 19 '15 at 7:59















                                                                        What would Math.round() do? It looks totally useless here.

                                                                        – Davide R.
                                                                        Jun 11 '15 at 10:44





                                                                        What would Math.round() do? It looks totally useless here.

                                                                        – Davide R.
                                                                        Jun 11 '15 at 10:44













                                                                        Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                        – Ferhat KOÇER
                                                                        Jun 12 '15 at 7:59







                                                                        Hi I used Math.round() Because Some Browser can cache Url - page so refresh not working.

                                                                        – Ferhat KOÇER
                                                                        Jun 12 '15 at 7:59






                                                                        4




                                                                        4





                                                                        I think you meant Math.random() lol

                                                                        – michelpm
                                                                        Jul 24 '15 at 1:51





                                                                        I think you meant Math.random() lol

                                                                        – michelpm
                                                                        Jul 24 '15 at 1:51





                                                                        protected by Community Aug 13 '15 at 16:01



                                                                        Thank you for your interest in this question.
                                                                        Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                                        Would you like to answer one of these unanswered questions instead?



                                                                        Popular posts from this blog

                                                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                                                        Alcedinidae

                                                                        Origin of the phrase “under your belt”?