Skip to main content

Call parent window’s javascript function from child window


Hi, I stuck with one requirement as describe in title and after searching for the solution, I found how can I call javascript function of the parent window whereas I am working with the child window. Here is the solution for you all.

Write below function of javascript in your parent window. We will call it later from the child.

    <script language=”javascript” type=”text/javascript”>
    function ParentWindowFunction()
    {
        alert(‘Hi, At least someone has called me from the child window’);
        return false;
    }
    </script>

Write the below code in your child window

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

You can call above function from a button click event like
    <input type=”button”  name=”btn1″ value=”Call Parent Window Function”onclick=”javascript:return CallParentWindowFunction();”/>

That’s it. Now by clicking on this child window’s button you can call a function resides in parent window.
Whether you found this article useful or not? please provide your valuable comments.

Comments