PDA

View Full Version : Auto reload a window in DHTML Window widget



Groo
01-09-2008, 05:37 PM
1) Script Title: DHTML Window widget (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/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:



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.

ddadmin
01-10-2008, 06:20 AM
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:


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:


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...

Groo
01-10-2008, 10:16 AM
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:


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.

Groo
01-11-2008, 08:44 AM
Anyone has a idea how to solve this? Thanks.

ddadmin
01-11-2008, 11:30 AM
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:


<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:


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()

Fixed typo per last post below

Groo
01-11-2008, 04:57 PM
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:


<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!!! :):):)