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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Montreal, QC
    Posts
    340
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Redirect Parent from Pop-Up

    Hi,

    I'm not really sure if this should be in the PHP forum or the Javascript forum. I'm posting here because I'm hoping there's a PHP solution to my problem.

    Here's how it goes: I have a page that when you click a link pops up a new window (using target="_blank"). In the new window is a form. What I want to have happen is when the user submits the form in the pop-up window the form is processed via PHP, the pop-up is closed, and the parent window is re-directed to the appropriate page depending on what was put into the form.

    I tried having the PHP in the pop-up end with:
    PHP Code:
    header("Location:javascript:opener.location.href='http://www.thenewurl.com/'"); 
    but that didn't work. Is there an easy way to do this that I'm not thinking of?

    Thanks in advance,

    John
    Search for Laughter or Just Search?
    GiggleSearch.org
    Blog: www.johnbeales.com
    All About Ballet: www.the-ballet.com

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,196
    Thanks
    12
    Thanked 109 Times in 107 Posts
    its really a javascript question (even though you may be writing the javascript with PHP)

    you need to open the popup with javascript (not target="_blank") to be able to control the parent from the popup , moving to javascript for more help.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  3. #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,079
    Thanks
    0
    Thanked 257 Times in 253 Posts
    The php should output this HTML.
    Code:
    <html>
    <head>
    <title>Processing done...Please wait.</title>
    <script type="text/javascript">
    function closeMe(){
      if (opener && !opener.closed) opener.location.href = "http://www.thenewurl.com/";
      window.close();
    }
    </script>
    </head>
    <body onload="setTimeout('closeMe()', 1000)">
    Processing done...Please wait.
    </body>
    </html>

  4. #4
    Regular Coder
    Join Date
    Apr 2003
    Location
    Montreal, QC
    Posts
    340
    Thanks
    3
    Thanked 2 Times in 2 Posts
    That makes sense. I had been hoping I could do it without having to output a bunch of HTML, but I can live with outputting a little like that.

    Thanks,

    John
    Search for Laughter or Just Search?
    GiggleSearch.org
    Blog: www.johnbeales.com
    All About Ballet: www.the-ballet.com

  5. #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,079
    Thanks
    0
    Thanked 257 Times in 253 Posts
    Quote Originally Posted by johnnyb
    That makes sense. I had been hoping I could do it without having to output a bunch of HTML, but I can live with outputting a little like that.

    Thanks,

    John
    You have to because obviously server-side cannot redirect a page to another window or frame. Server-side has nothing to do with the window/frame setup, it's a client-side thing so the solution must be client-side.

  6. #6
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts
    How would you do the exact same thing without having the window close?

    Thanks so much!
    -Johnny
    Last edited by JohnnyM; 10-31-2008 at 12:28 AM.

  7. #7
    Regular Coder
    Join Date
    Apr 2003
    Location
    Montreal, QC
    Posts
    340
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Just remove window.close() from the script above.
    Search for Laughter or Just Search?
    GiggleSearch.org
    Blog: www.johnbeales.com
    All About Ballet: www.the-ballet.com

  8. Users who have thanked johnnyb for this post:

    JohnnyM (10-31-2008)


 

Posting Permissions

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