Results 1 to 6 of 6

Thread: Auto reload a window in DHTML Window widget

  1. #1
    Join Date
    Jan 2008
    Location
    Motril, Granada, Spain.
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Auto reload a window in DHTML Window widget

    1) Script Title: DHTML Window widget (v1.1)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ndow/index.htm

    3) Describe problem:

    Hello, DHTML Window Widget works great for my purposes, I have been using "AJAX Content option" to show windows with values captured from external board (USB data adquisition board) for some days and I am very happy.

    The problem is that I need to refresh the content from this windows periodically and I don't know how. I have tried using <meta http-equiv="refresh" content="2"> in the web page called (prueba.htm) from the script:

    Code:
    function openEnDig0()
           {
            ajaxwin=dhtmlwindow.open("ajaxbox2", "ajax", "prueba.htm", "Entrada Digital 0", "width=250px,height=150px,left=10px,top=50px
    ,resize=1,scrolling=1")
           }
    But it don't work... Anyone can help me with this issue, I only need that prueba.htm, loaded in a floating window, could be relloaded automatically every X seconds.

    Thanks, and sorry for my bad english.
    Groo.

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    You can get the DHTML window to reload/ refetch the external page using Ajax every x seconds basically just by calling load() every x seconds:

    Code:
    ajaxwin.load('ajax', 'prueba.htm', 'Entrada Digital 0')
    The trick is to also take into account if/when the DHTML window has been closed, and stop this process as well. With that in mind, you'd have something like this:

    Code:
    function openEnDig0(){
            ajaxwin=dhtmlwindow.open("ajaxbox2", "ajax", "prueba.htm", "Entrada Digital 0", "width=250px,height=150px,left=10px,top=50px
    ,resize=1,scrolling=1")
            reloadwindow()
    }
    
    function reloadwindow(){
           if (typeof ajaxwin!="undefined" && ajaxwin.isClosed!=true){
           ajaxwin.load('ajax', 'windowfiles/external2.htm', 'New Ajax Page')
           setTimeout("reloadwindow()", 1000)
           }
    }
    The parts in red are new...

  3. #3
    Join Date
    Jan 2008
    Location
    Motril, Granada, Spain.
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face

    Thanks for your answer,
    Your code works very well when im using a single dhtml window, but when i have multiple windows opened, the content of the first, second or even third windows are refreshed always in the last window the user opened.

    here is the code I used:
    Code:
        function reloadwindow0()
         {
          if (typeof ajaxwin!="undefined" && ajaxwin.isClosed!=true)
           {
            ajaxwin.load('ajax', 'contenido/endig0.php', 'Entrada Digital 0')
            setTimeout("reloadwindow0()", 5000)
           }
         }
    
        function reloadwindow1()
         {
          if (typeof ajaxwin!="undefined" && ajaxwin.isClosed!=true)
           {
            ajaxwin.load('ajax', 'contenido/endig1.php', 'Entrada Digital 1')
            setTimeout("reloadwindow1()", 5000)
           }
         }
    
        function reloadwindow2()
         {
          if (typeof ajaxwin!="undefined" && ajaxwin.isClosed!=true)
           {
            ajaxwin.load('ajax', 'contenido/endig2.php', 'Entrada Digital 2')
            setTimeout("reloadwindow2()", 5000)
           }
         }
    
          function openEnDig0()
           {
            ajaxwin=dhtmlwindow.open("ajaxbox2", "ajax", "contenido/endig0.php", "Entrada Digital 0", "width=250px,height=150px,left=10p
    x,top=50px,resize=1,scrolling=1")
            reloadwindow0()
           }
    
          function openEnDig1()
           {
            ajaxwin=dhtmlwindow.open("ajaxbox3", "ajax", "contenido/endig1.php", "Entrada Digital 1", "width=250px,height=150px,left=10p
    x,top=150px,resize=1,scrolling=1")
            reloadwindow1() 
           }
    
          function openEnDig2()
           {
            ajaxwin=dhtmlwindow.open("ajaxbox4", "ajax", "contenido/endig2.php", "Entrada Digital 2", "width=250px,height=150px,left=10p
    x,top=250px,resize=1,scrolling=1")
            reloadwindow2()
           }
    I need to have 6 or 7 dhtml windows opened simultaneous.

    Thanks again.

  4. #4
    Join Date
    Jan 2008
    Location
    Motril, Granada, Spain.
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face

    Anyone has a idea how to solve this? Thanks.

  5. #5
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Yep, the code I provided was just an example of how it would work, with hard coded values. You can use the below, more generic modified function instead:

    Code:
    <script type="text/javascript">
    
    function reloadwindow(winvar, url, title, sec){
    if (typeof winvar!="undefined" && winvar.isClosed!=true){
    winvar.load('ajax', url, title)
    setTimeout(function(){reloadwindow(winvar, url, title, sec)}, sec)
    }
    }
    
    </script>
    Don't duplicate this function on your page. Then inside any function that opens a Ajax DHTML window, you can get it to reload every x sec by doing something like:

    Code:
    function openEnDig0(){
    ajaxwin=dhtmlwindow.open("ajaxbox2", "ajax", "prueba.htm", "Entrada Digital 0", "width=250px,height=150px,left=10px,top=50px
    ,resize=1,scrolling=1")
    reloadwindow(ajaxwin, "prueba.htm", "Entrada Digital 0", 2000)
    }
    Note the part in red- they need to match up for each function that's calling reloadwindow()

    Edit: Fixed typo per last post below
    Last edited by ddadmin; 01-11-2008 at 11:49 PM.

  6. #6
    Join Date
    Jan 2008
    Location
    Motril, Granada, Spain.
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thanks, now it works great, even with lot of dhtml windows open.

    I detect a little bug in your reload function, allow me to notify it for other users may need this feature:

    Code:
    <script type="text/javascript">
    function reloadwindow(winvar, url, title, sec){
    if (typeof winvar!="undefined" && winvar.isClosed!=true){
    winvar.load('ajax', url, title)
    setTimeout(function(){reloadwindow(winvar, url, title, sec)}, sec)
    }
    }
    </script>
    Thanks again!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •