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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with window.opener in Firefox/Mozilla

    First a basic outline of what I am trying to do:

    I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit" on the pop-up's form I want the pop-up to close & a new page to load in the "parent" window/page. I have this working in IE but cannot get it to work in Firefox. The parent window correctly loads the new page after submitting from the pop-up, however the pop-up will not close. Here is what I have in my pop-up page:

    <body bgcolor=#fffff0 onLoad="window.opener.name='mainPage';window.opener.opener=window">

    Basically giving a name to the parent window & then setting the parent window's opener to the pop-up. Here is my form tag for the pop-up page:

    <form action=geturls.jsp target="mainPage" onSubmit="return validate(this)">

    So now the target of the submission from the pop-up is the initial parent window. The next page which loads in the parent window (after submitting from the pop-up) has the following body tag:

    <body bgcolor=#fffff0 onLoad="javascript:window.opener.close()">

    Since I set the pop-up as the opener of the parent window from the pop-up html with the tag I show above, this should work. It does work perfectly in IE but in Firefox the pop-up stays open & I get the following javascript error:

    window.opener has no properties

    I am using Firefox 0.9.3.

    Thanks!

  • #2
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    P.S. I should also mention that the "validate()" method in pop-up needs to return "true" if there are no validation errors with the pop-up's form & then post the form to the main page since it loads a *different* page (i.e. it doesn't just reload the page already loaded in the parent window), so I cannot just call "window.close()" in this function.

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Basically giving a name to the parent window & then setting the parent window's opener to the pop-up. Here is my form tag for the pop-up page:

    What?





    I want to have a page spawn a pop-up when you click "submit" on its form. On this pop-up page there will be another form. When you click "submit" on the pop-up's form I want the pop-up to close & a new page to load in the "parent" window/page

    I realize you have a form validation scripts involved (which you haven't provided), but just write the following logic into them:


    Main Page:

    Code:
    <form onsubmit="javascript:window.open('somePage.html','','');">
    <input type=submit>
    </form>
    Popup:

    Code:
    <form onsubmit="javascript:window.opener.location.href='yourNewPage.html';self.close();">
    <input type=submit>
    </form>
    This will work in both browsers.


    -james
    Last edited by jamescover; 08-31-2004 at 10:17 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,966
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Quote Originally Posted by fogwolf
    So now the target of the submission from the pop-up is the initial parent window. The next page which loads in the parent window (after submitting from the pop-up) has the following body tag:

    <body bgcolor=#fffff0 onLoad="javascript:window.opener.close()">
    Try changing it to:

    <body bgcolor=#fffff0 onLoad="w=window.open('','TheNameOfPopup');w.close()">

    That will re-acquire the window handle of the popup and it will now be able to call the close() method. So no need for the popup to set itself as the opener of the parent window.

    Now if that page will be called by other pages, you have to dynamically generate (in the server-side) that onload handler if only the referring page is the popup or by any other means.


  •  

    Posting Permissions

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