4 Replies Latest reply on Feb 17, 2010 5:58 AM by Catalin Anastasoaie

    Auto page refresh with javascript


      Hey All,


      I've been working on building an air app that loads up a website and performs certain operations.  It's built for the most part using the following:


      http://help.adobe.com/en_US/AIR/1.5/devappshtml/WS5b3ccc516d4fbf351e63e3d118666ade46-7ecc. html


      In addition to this, I've added something that loads the window as always on top, and an auto refresh. This is where I hit the problem


      I have the main html file that the air app loads set to create a frameset, with a single frame at 100% currently, and that frame is an external page, so in effect the app is displaying an externally hosted page and little more at this point.


      I struggled all day trying to get the auto refresh to work, and never could, until tonight I found out the cause.


      The code is as follows:



        var timer = window.setInterval("autoRefresh()", 5000 );
        function autoRefresh(){



      This actually works, *as long as* the src for the frame sebFrame is a local page. If I use an externally hosted page, it simply doesn't reload, and also there are no console errors when I'm running adl.


      I've been crawling up and down google all day and night and after much testing found this to be the case. So, does anyone know why auto refresh would fail to work here for an external page, but work for a local html file, and more importantly, how I can work around whatever limitation this is? Bear in mind that I can't modify the content of the externally hosted site.


      Lastly, the 5000ms seems small, but is only that way for testing purposes; the intent is to have this reloading once every 15 minutes once working.


      Any help is greatly appreciated.

        • 1. Re: Auto page refresh with javascript
          brookssw Level 1

          Also worth noting is that it doesn't have to be javascript to make it work, I can be flexible, but I'm desperate now, haha


          It seems that the frame reference isn't taking, because if I put a bad statement in there I can see that the timer is running on queue, but the target frame isn't being reloaded.

          • 2. Re: Auto page refresh with javascript
            Catalin Anastasoaie Adobe Employee



            The issue you are encountering is a restriction related to the way in which the browsers have implemented the cross domain policies thus limiting access to some functions (in our particular case - the reload() function) when loading content from another domain. This explains why your application is working correctly when using the local resource and not working when using a remote resource.


            But there is an workaround for this: instead of trying to reload the location of the <frame> you could re-set the "src" with the same location at every 5 sec.


            Your code will become:


            var timer = window.setInterval(autoRefresh, 5000);



            function autoRefresh(){




            Hope this helps,


            1 person found this helpful
            • 3. Re: Auto page refresh with javascript
              brookssw Level 1

              That does help, thank you!


              It raises another question though; the URL I'm referencing changes after initial load (I login, and it then includes a necessary session ID in the URL).


              I've tried to reference itself, and also the URL of another frame, to no avail. What you suggest works just fine with a static URL, but when I try something like the following, it doesn't do anything:




              Any idea how I can:


              1. grab the url after the session id has generated and the correct page is loaded, including the session id

              2. reference said URL to fire the reload


              Thanks again, and any other assistance is very much appreciated

              • 4. Re: Auto page refresh with javascript
                Catalin Anastasoaie Adobe Employee

                Maybe the following workaround can help you with your use case:


                function onLoad(){

                     var url = document.getElementById('singleFrame').src;

                     var timer = window.setInterval(autoRefresh, 5000);



                     alert("onLoadURL: " + url);



                     function autoRefresh(){

                          url = document.getElementById('singleFrame').contentWindow.location.href;


                          alert("onRefreshURL: " + url);


                          document.getElementById('singleFrame').src= url;





                Hope this helps,