Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh a particular div after closing a modal window?

Tags:

javascript

I have a modal window which closes when i add an item. The parent page will refresh once the modal window is closed. But i don't want the whole window to get closed, but i want a particular div to get refreshed. is there any javascript way to do it ?

like image 938
Bala Avatar asked Dec 04 '25 18:12

Bala


1 Answers

You can call a javascript method in the parent window while closing the child window. This is very simple.

You can have a javascript method to refresh the content of the div

<script language=”javascript” type=”text/javascript”>
function ParentWindowFunction()
{
    alert(‘Need to refresh targetdiv. I am instructed from child window’);
    //refresh the div
    return false;
}
</script>

And in the child window, you may have some button to close that window and also can call up the parent window's javascript

<script language=”javascript” type=”text/javascript”>
function CallParentWindowFunction()
{
    window.opener.ParentWindowFunction();
    return false;
}
</script>

<input type=”button”  name=”btn1″ value=”Call Parent Window Function” onclick=”javascript:return CallParentWindowFunction();”/>
like image 167
Kangkan Avatar answered Dec 06 '25 08:12

Kangkan