11 Replies - 1175 Views - Last Post: 28 March 2015 - 11:22 AM

#1 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

How to close a popup page?

Posted 18 March 2015 - 03:43 PM

Hi guys,

I need your help, I want to close a page when a button is pressed. I'm using the script `add_address.php` to output a list of email addresses from the `message` box and I want to output the email addresses to the `text` box in the `send.php` script


Here is the code for add_address.php:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Add Email Addresses...</title>
        </head>
        <body>
        <form action="send.php" method="post">
        <table>
            <tr>
                <td><textarea name="message" cols="50" rows="20"></textarea></td>
                
            </tr>
            
            <td colspan="2" align="left">
               <input type="submit" name="send" value="Add Email" style="height:35px; width:100px">
            </td>
        </table>
        </form>
        </body>



Here is the code for send.php:

    <?php
        if (!empty($_POST['message'])) 
        {
            $emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
            $email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
         }
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Send Email</title>
    	<link type="text/css" rel="stylesheet" href="style.css"  />
        </head>
        <body>
        <form action="pr_send.php" method="POST">
        <table>	
            <!-- <tr>
                <td>From:</td>
                <td><input type="text" name="from"></td>
            </tr> -->
            <tr>
                <td><input type="button" name="to" value="" style="height:24px; width:24px; background:url('addressbook.png'); border:none;" onclick="Popup()"> To:</td> 
                <td><input type="text" name="to" value="<?php if (!empty($email_str)) { echo $email_str; } ?>" style="height:15px; width:650px"></td>
            </tr>
            <tr>
                <td>Subject:</td>
                <td><input type="text" name="subject" style="height:15px; width:650px"></td>
            </tr>
            <tr>
                <td>Message:</td>
                <td><textarea name="message" cols="90" rows="20"></textarea></td>
            </tr>
            <tr>
                <td colspan="2" align="left">
                   <input type="submit" name="send" value="" style="height:35px; width:100px; background:url('send.png'); border:none">
                </td>
            </tr>
    
        </table>
        </form>
        </body>
    <script type="text/javascript">
    function Popup() 
    {
      window.open("add_address.php", "_blank", "toolbar=yes, scrollbars=yes, resizable=yes, top=100, left=500, width=400, height=400");
    }
    </script>
    
    </html>




What my snippets have show, it will only allowed me to output the list of email addresses in the `message` box and it will redirect to the `send.php` page to output the list of email addresses in the `text` box without close it.

Is This A Good Question/Topic? 0
  • +

Replies To: How to close a popup page?

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2754
  • View blog
  • Posts: 8,056
  • Joined: 15-January 14

Re: How to close a popup page?

Posted 18 March 2015 - 03:50 PM

If you want to close a popup window that was opened with Javascript then you need to save a reference to the window that you can use later. e.g.:

var popup = null;
function openPopUp() {
  popup = window.open(...);
}
function closePopUp() {
  if (popup) {
    popup.close();
  }
}


You can also just use window.close to close the current window.
Was This Post Helpful? 0
  • +
  • -

#3 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: How to close a popup page?

Posted 18 March 2015 - 03:54 PM

Thank you very much for this, which script `add_address.php` or `send.php` and in which line of code that I need to get rid and replace with the javascript?
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2754
  • View blog
  • Posts: 8,056
  • Joined: 15-January 14

Re: How to close a popup page?

Posted 18 March 2015 - 04:07 PM

That's just an example showing how to do it in general. I don't know what specifically you want to do. You already have a call to window.open in your popup function, so if you wanted to have a button to close that window then you could save the window like I showed and close it later. If you want the popup window to close itself when something happens, like when you submit the form, then you could have PHP output a call to window.close to close it. It depends how you want it to work.
Was This Post Helpful? 0
  • +
  • -

#5 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: How to close a popup page?

Posted 18 March 2015 - 04:33 PM

Ok, when I fill the email addresses in a message box and when I click on a submit button, how do you close the popup when I post the message using this code?

    if (!empty($_POST['message'])) 
    {
        $emails = explode("\n", $_POST['message']); // explode textarea on a line break into an array
        $email_str = implode(", ", $emails); // take each of the emails and implode together with the ,
    }


This post has been edited by mark103: 18 March 2015 - 04:42 PM

Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2754
  • View blog
  • Posts: 8,056
  • Joined: 15-January 14

Re: How to close a popup page?

Posted 18 March 2015 - 05:01 PM

After you're done processing the form all you need to do is have PHP output a shell HTML page structure with a line of Javascript that calls window.close, that will close the current window.

https://developer.mo...PI/Window/close

Any window object has a close method, but if you specifically use window.close() then window refers to the current window.

Part of the reason why I'm a little confused is because you have a form on send.php, and the links open popups to add_address.php, which has a form that submits back to send.php. It seems like a loop between send.php and add_address.php that keeps opening new popups. If you want to close any of those windows just output a Javascript call to window.close.
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6872
  • View blog
  • Posts: 31,656
  • Joined: 10-May 07

Re: How to close a popup page?

Posted 18 March 2015 - 05:03 PM

You can't close a pop-up page from php.
Was This Post Helpful? 0
  • +
  • -

#8 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: How to close a popup page?

Posted 18 March 2015 - 05:50 PM

View Postno2pencil, on 18 March 2015 - 05:03 PM, said:

You can't close a pop-up page from php.



So how I can close a popup page when I want to output a message from add_address.php to output in a message in send.php?

Example: I click on a address book button to pop up a page to allow me to fill the list of email addresses like this:

Posted Image


When I click on a submit button, it didn't close the popup to output the email addresses from a message box to a text box where you can see it:

Posted Image


Hope you can help me to fix the problem?
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6872
  • View blog
  • Posts: 31,656
  • Joined: 10-May 07

Re: How to close a popup page?

Posted 18 March 2015 - 06:46 PM

The concept of a 'pop-up' is client side coding. Javascript, jquery modal, html, you are creating an effect in the client browser. Controlling it dynamically (popping it open, closing it) are concepts that have nothing to do with php.

Moving topic to html/css.
Was This Post Helpful? 0
  • +
  • -

#10 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: How to close a popup page?

Posted 20 March 2015 - 01:32 PM

Does anyone know how I can close a popup page when I want to output the email addresses in a message box from add_address.php to output it in a text box in send.php?
Was This Post Helpful? 0
  • +
  • -

#11 mark103   User is offline

  • D.I.C Head

Reputation: -10
  • View blog
  • Posts: 107
  • Joined: 13-April 08

Re: How to close a popup page?

Posted 28 March 2015 - 09:21 AM

Anyone????????????
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15781
  • View blog
  • Posts: 63,250
  • Joined: 12-June 08

Re: How to close a popup page?

Posted 28 March 2015 - 11:22 AM

Perhaps you need to explain more clearly what you are doing.

So what - is this an attempt at automating some mass mailing app?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1