PDA

View Full Version : Refresh Calling page



kevin_dalby
01-18-2008, 11:01 PM
1) Script Title: DHTML Window Widget

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

3) Describe problem:

script works beautifully !!

but, i want to refresh the page that called the window after the window is closed.

what i'm looking for is this chain of events:

Parent Page loads which has link that uses the Window Widget...
click on link, window opens, data form presented, user inputs data, done with that page - close window,
after the window closes I want the page that called it to refresh since there were probably some updates made in the window (via a form) that affect the list of data on the calling page.

I tried doing this in the dhtmlwindow.onclose() event - but i think it was erroring out since i was asking for a window.location.reload() while it was closing.

Does anyone know how to call a simple function after the DHTML Window has close. Is there an after close event that can be captured.

thanks
kevin

thetestingsite
01-18-2008, 11:22 PM
window.opener.reload() perhaps?

kevin_dalby
01-19-2008, 12:59 AM
tried that in place of the return window.confirm("Close this window?") but, it didn't seem to work

jscheuer1
01-19-2008, 05:54 AM
If the code is on the page that you want reloaded:


setTimeout(function(){window.location.reload(true);},100);

kevin_dalby
01-19-2008, 12:06 PM
Can you tell me how/where that fits the script which structure is like this:
( loose syntax here)

function mywindowopener()
myvar=dhtmlwindow.open( 'w2','ajax' ...my parameters...)
myvar.onclose=function(){
....function statements go here ....
}

if your intent was to refresh the page every x seconds, that won't work - refreshes seem to close the child windows

jscheuer1
01-19-2008, 01:53 PM
function mywindowopener()
myvar=dhtmlwindow.open( 'w2','ajax' ...my parameters...)
myvar.onclose=function(){
setTimeout(function(){window.location.reload(true);},100);
}

setTimeout only executes once, but is delayed. I think you are confusing this with setInterval. Even setInterval would work here, as once a page is refreshed, the interval ends.

However, if you want to reload the page, yes that will return it to its normal first load state, except that any server side and javascript cookie data that the page is configured to respond to, if any of that has been updated, the page will now respond to that updated data.

But that will only reload the page that this code is on. If you want to reload another page, you must have a reference to it, and you must execute its refresh before the page that is refreshing its window closes.

So, you might want to have:


function mywindowopener()
myvar=dhtmlwindow.open( 'w2','ajax' ...my parameters...)
myvar.onclose=function(){
window.opener.location.reload(true);
setTimeout(function(){window.close();},100);
}

It's a little confusing because I'm not clear on what type of window(s) you are referring to, actual and/or virtual, or where the code is and what window object(s) it is supposed to do what to.

If you need more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

jscheuer1
01-19-2008, 02:20 PM
To understand the relationship between actual windows in this regard, try these two pages:

test.htm:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload=function(){alert('I\'ve just Loaded!');};
</script>
</head>
<body>
Test HTML Content<br>
<a href="test_closed.htm" onclick="window.open(this.href,'_blank');return false;">TC</a>
</body>
</html>

test_closed.htm


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
window.onload=function(){
window.opener.location.reload(true);
setTimeout(function(){window.opener.document.body.style.backgroundColor='pink';},200);
setTimeout(function(){window.close();},500);
}
</script>
</head>
<body>

</body>
</html>

Opening test.htm will fire its onload alert.

Clicking on the link TC will open test_closed.htm in a new window, which will:


reload test.htm, firing test.htm's onload alert
turn test.htm's background pink
close itself (test_closed)