CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Question parent document question...

    I created a form, that opens a new window with some more options...

    now, once the user pushes a button on the newly opened window, I want some thins to happen in the main form window.

    I know that if I want some values to change, all I need to do is :
    parent.opener.document.getElementById("UserInput").value = usrValue;

    now I wanna know, how to run a certain function on the main window, once a button on the new window was pushed???



    thanks, gilly914
    Rate this post if you found it useful!
    10X, gilly914

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: parent document question...

    To my knowledge this is impossible. I do not have time to research it now but I can look into it after work. The only thing I have ever seen is working with objects from other windows, never actual JavaScript function calls from other windows. Sorry.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: parent document question...

    I just solved my problem, almost as usual, in a different way...

    I just created a setInterval() to a function on the main window that checks if a certain flag is changed on the new window...
    Than it knows when to activate...

    Thanks for the help anyway...
    Rate this post if you found it useful!
    10X, gilly914

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: parent document question...

    Good thinking. I was thinking of using setTimeout but then I realized it couldn't be created dynamically. Then I thought to myself why not write it dynamically to a DIV?

    Okay, here is another option... On the parent page create a DIV.

    Code:
    <div id="dynwrite" style="visibility:hidden"></div>
    Now in the popup window write this...

    Code:
    <script language="JavaScript">
    newhtmlline = "<script language='JavaScript'>";
    newhtmlline = newhtmlline + "setTimeout('FUNCTIONNAME', 10);"
    newhtmlline = newhtmlline + "</script>";
    parent.opener.document.getElementByID('dynwrite').innerHTML = newhtmlline;
    </script>
    Last edited by peejavery; January 26th, 2006 at 11:09 AM.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: parent document question...

    Note that I edited my previous post and this will keep you from having to have an interval running and taking up resources.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Jul 2004
    Location
    Holy Land
    Posts
    306

    Re: parent document question...

    WOW!...

    Thanks alot! You always supply me with good and creative solutions...

    Thanks peejavery
    Rate this post if you found it useful!
    10X, gilly914

  7. #7
    Join Date
    May 2002
    Posts
    10,943

    Re: parent document question...

    Quote Originally Posted by gilly914
    WOW!...

    Thanks alot! You always supply me with good and creative solutions...
    Thank you too!
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  8. #8
    Join Date
    Jul 2004
    Location
    Mumbai
    Posts
    11

    Re: parent document question...

    This would look silly..
    Keep a hidden button in the parent which calls a function on click.
    Click this button from the popup.

    as simple as that if u want it that way.

  9. #9
    Join Date
    May 2002
    Posts
    10,943

    Re: parent document question...

    Quote Originally Posted by amitvb
    Keep a hidden button in the parent which calls a function on click.
    Click this button from the popup.
    Nice one. I tried the code below and it works nicely.

    Code:
    <input id="execbutton" type="button" value="Click Here" onclick="alert('It Worked!')" style="display:none">
    
    <script language="JavaScript">
    document.getElementById('execbutton').click();
    </script>
    One other thing, newer browsers even accept function calls between windows. I just found it and I never knew about it even though it seemed dumb to not work this way.

    All you have to do is call the window's name and then the function.
    Code:
    windowname.window.function();
    Sorry gilly914 for making that one hard on you.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured