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.

Advertisements
Comments
  1. moni says:

    parent.myfunction(); works fine when called from child iframe in IE and FF but it doesn’t work with safari.

  2. Carmen says:

    Hi,

    I have done this and I get an error: “window.opener” is null or not an object.

    The child is called from a IFrame of a Parent.

    Thanks.

  3. KIRAN says:

    parent.function() works for me.

  4. henry says:

    what about document.write with this?

  5. dude says:

    a demo of the thing would have helped me. or a complete code in a zip file could have helped me.

  6. Marlon says:

    it works fine thanks!

  7. iktiar says:

    thanks man…
    i was looking for something like that!

  8. milan says:

    This really works 100 percent perfectly. thank you so much, it made my job easier and saves alot of time.

  9. kumar says:

    Hi all,

    can you guys explain me what is working and what not..
    I have a javascript functions in Basepage.aspx so I inherits from child page
    “trying to call Parentwindowfunction from Basepage to child window which is a popup( another aspx acts a popup)”
    i get a null or invalid object. Can someone help me out of this..

    • Shane Herron says:

      Not sure exactly what you mean by “inherit from child page”; but the parent page should never inherit from the child page. If that’s what you’re doing then you’re inheriting in the wrong direction. Think of it like this; that’s like you inheriting from your father; doesn’t work that way.

  10. netsi1964 says:

    Hi,
    I guess that it will work if the parent and child window are within same domain, otherwise the function call will be blocked because of cross domain scripting issues.

  11. Satya Siddhantar says:

    This function works in firefox fine although in error console it generates an error
    But doesnt support in IE
    If any one have suggestion for this then help me…

  12. Danyal says:

    Thats what i was looking for.
    Good work

  13. Shane Herron says:

    Completely solved my problem; I’d searched for hours and tried dozens of different methods with no luck. This article not only provided the answer; but it’s so simple I’m ashamed of myself for not thinking of it on my own.

  14. Pravin Sreedharan says:

    hi all, window.parent.function() works well for me

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s