Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    assign event handler from child to parent window

    Is it possible to assign an event handler from a child window to a parent window?

    I am using something like this:

    var elem = window.opener.document.createElement("input");
    elem.setAttribute('type','button');
    elem.setAttribute('value','Upload Image');
    elem.setAttribute('name','upload');
    elem.setAttribute('onClick','uploadOpen();');
    window.opener.document.getElementById ("uuimage").appendChild (elem);

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    elem.onclick=uploadOpen;
    or if u need more functions or to pass a paramater:
    elem.onclick=function(){uploadOpen();anotherfunction(parameter)};
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that before posting. Does not work. I read a comment somewhere about not being able to attach events from child to parent windows. Can anyone verify this?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Then try seting the event handler after the appending

    var root = window.opener.document.getElementById ("uuimage");
    var elem = window.opener.document.createElement("input");
    elem.setAttribute('type','button');
    elem.setAttribute('value','Upload Image');
    elem.setAttribute('name','upload');
    elem.setAttribute('id','upload');
    root.appendChild (elem);
    root.getElementById('upload').onclick=function(){opener.uploadOpen()};
    Last edited by Kor; 02-23-2005 at 11:03 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    _Gecko:

    First, what document does the uploadOpen function reside in? Second, can you show us it's source?
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Liorean is right. I presumed that the function is on opener... If so, the code will definetely work. (i mean the refrences are correct, but I don't know if the goal is correct.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help. I have already solved the problem, but out of curiosity I am goign back to see if this does in fact work.

    The uploadOpen function is indeed in the opener.

    The way I solved the problem is to do a refresh of the opener. I read someone's comment somewhere that they lost any values entered into a form on the opener page when a refresh was forced. The way I solved this problem was to capture all fields on the opener form to variables, then do a parent refresh like so:

    window.opener.document.location = window.opener.document.location;

    then rebuild all the opener form values via setTimeout() calls.
    Ex: setTimeout("window.opener.document.MYFORM.__MYFIELD__.value = stored_value_for__myfield__",1250);

    then after all fields are populated, do a setTimeout("self.close()",1250);

  • #8
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you verify that this does in fact not work:

    test.html:
    <html><head><title>test</title></head>
    <body><a href="#" onClick="uploadWin = window.open('test2.html', 'winop', 'width=500,height=200,left=300,top=250,scrollbars=auto,statusbar=yes,resizable=yes');">this is a test of the event handler</a><br><div id="uuimage">&nbsp;</div></body></html>


    test2.html:
    <html><head><title>test</title>
    <script language="JavaScript">
    function test() {
    var root = window.opener.document.getElementById ("uuimage");
    var elem = window.opener.document.createElement("input");
    elem.setAttribute('type','button');
    elem.setAttribute('value','Upload Image');
    elem.setAttribute('name','upload');
    elem.setAttribute('id','upload');
    root.appendChild (elem);
    root.getElementById('upload').onclick=function(){alert('x')};
    self.close();
    }
    </script>
    </head>
    <body onLoad="test();"></body></html>


  •  

    Posting Permissions

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