#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0

    javascript popup window reusing from multiple openers?


    good afternoon!

    i have a small problem and i was wondering if anyone here has a neat solution.

    i have 2 pages on a website. call them page1 and page2. they can't be in a frameset at all (the are seperate windows)

    on each of these windows, i would like to allow people to popup a 'remote control' type window which can reference the window's opener (it's a search window, and it'll put the found results directly into a text box)

    the window open code is (identical for page1 and page2)

    -----

    var remote=null;

    function open_window(theURL,winName,features) { //v2.0
    remote=window.open(theURL,'rs_'+winName,features);
    remote.myParent=window;
    if (remote.opener == null) { remote.opener = window; }
    remote.focus();
    }

    -----

    and on the window i have

    -----

    if (typeof(myParent)=="undefined") { myParent=window.opener; }

    function showresult(result) {
    if (typeof(myParent)!="undefined") {
    // do stuff here to myParent.document.form...
    }
    }

    -----

    ok, the problem is this.

    say i'm on page1, i click the window open button, it pops up and works perfectly. i leave the remote window open.

    i stay on page1, i click the window open button again. this time, myParent is set to undefined (hence the if (typeof(myParent)=="undefined") { myParent=window.opener; } line) - so that workaround seems to do the trick.

    but the real problem occurs if i leave the window open and go to page2 and click the 'popup remote' button. the remote again thinks myParent is null/undefined, but window.opener is still set to page1.

    if i close the window and re-open it from the new page it works fine.

    however, the remote.focus() method works fine and brings the remote to the front, so it's obviously acquiring the 'remote' variable correctly. it just seems that any window aside from the opener can't actually do anything to the variables in the newly-opened - am i right?

    thanks for any help!
    Last edited by sengoku; October 1st, 2003 at 11:28 AM.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2003
    Posts
    802
    Rep Power
    104
    Perhaps you could make a function in the remote and pass it the window object, and the function could take care of setting myParent.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    2
    Rep Power
    0
    Originally posted by Clone53421
    Perhaps you could make a function in the remote and pass it the window object, and the function could take care of setting myParent.
    neat idea...

    -----
    this is the new opener function
    -----

    function open_window(theURL,winName,features) { //v2.0
    remote=window.open(theURL,'rs_'+winName,features);
    remote.myParent=window;
    remote.setMyParent(window);
    if (remote.opener == null) { remote.opener = window; }
    remote.focus();
    }

    -----
    and this in the popup
    -----

    if (typeof(myParent)=="undefined") { myParent=window.opener; }

    function setMyParent(objNewParent) {
    myParent=objNewParent;
    }

    -----

    still no luck though
    Last edited by sengoku; October 1st, 2003 at 12:43 PM.

IMN logo majestic logo threadwatch logo seochat tools logo