views:

133

answers:

3

Hi,

Is it possible to refresh parent page from child's child page using javascript.

I have a webform which opens a child window, a button on child window closes the present child window and opens a subchild window. Now a button on subchild should close the window and refresh the parent form.

Please suggest me the way of doing it.

Thank You.

For button click event

Code in Parent Page

function fun()

{
 window.open('Child.aspx');    
 return false;
}

Code in child page

function fun()

{
 window.close();
 window.open('SubChild.aspx');     
 return false;
}
+1  A: 

Have you tried using these?

window.opener.reload();

window.opener.location.reload();

I think window.opener.opener.reload(); may work..

Tim
Ya, I used them. But it is valid only for one patent-child.
Nani
Does window.opener.opener.reload(); not work?
Tim
A: 

EDITED after seeing your code. The problem is you're opening the 2nd window from the 1st window and closing the 1st window so you have no reference back to the opener. You can instead call a method in your Parent window to open the 2nd window, that way the Parent is still your opener.

Parent.html

function openWindow(sURL){
  window.open(sURL);
}

Child1.html

function fun(){
  window.opener.openWindow('Child2.html');     
  window.close();
}

Child2.html

function fun(){
  window.opener.location.reload(true);     
}
Shawn Steward
Its giving error."Breaking at jscript runtime. Access Denaied"
Nani
Please show us the code you use to open the window.
Shawn Steward
I edited my question, Pls check
Nani
Ok, I updated my answer based off your code. Try that out.
Shawn Steward
sorry, same problem Shawn .
Nani
Where do you get the error exactly? What line?
Shawn Steward
+1  A: 

Use following in your child window.

<script type="text/javascript">
    function openwindow()
    {
        opener.document.location.reload(true);
    }
</script>

EDITED

create two files 1] parent.html

<script type="text/javascript">
    function openwindow(url)
    {
    window.open(url, "mywindow","location=1,status=1,scrollbars=1,resizable=no,width=650,height=650");
    }
</script>


<a href="javascript: openwindow('/home/Salil/Desktop/child.html')">Open Child</a>

2] child.html

<script type="text/javascript">
    function openwindow()
    {
        opener.document.location.reload(true);
    }
</SCRIPT>

<a href="javascript: openwindow()">Refresh Parent</a>

EDITED LATEST

write a function in child1.html

function child1()
    {
        opener.document.location.reload(true);
    }

call that function form child2.html as follows

function child2()
{
    window.opener.child1();

}
Salil
Is it before opening SubChild Window?
Nani
Salil
I wanted to refresh parent from child's child window
Nani
Please check my EDITED LATEST Answer
Salil