Connecting Tech Pros Worldwide Forums | Help | Site Map

Closing window

Sheldon Glickler
Guest
 
Posts: n/a
#1: Feb 21 '06
Here is a problem I encounter often but haven't solved.

In a form I have a submit button. When clicked, I want to do some processing
so I check with the isset($_POST['the_button_name']). (I keep all my code
above the html code). Now, once I have done that processing, I want the
window to disappear. Is it as simple as adding an on_click event to close
the window? Will the processing then still take place?

Shelly



d
Guest
 
Posts: n/a
#2: Feb 21 '06

re: Closing window


"Sheldon Glickler" <sheldonlg@bellsouth.net> wrote in message
news:6XHKf.18061$UD1.9984@bignews2.bellsouth.net.. .[color=blue]
> Here is a problem I encounter often but haven't solved.
>
> In a form I have a submit button. When clicked, I want to do some
> processing so I check with the isset($_POST['the_button_name']). (I keep
> all my code above the html code). Now, once I have done that processing,
> I want the window to disappear. Is it as simple as adding an on_click
> event to close the window? Will the processing then still take place?[/color]

If the window was not opened with javascript, you might get a warning if you
try to close it.

The best (only?) way to close it in this situation is to spit out some
javascript after you process the $_POST:

<script type="text/javascript">
window.close();
</script>

and then exit your script. Your window will then close after the processing
has been done.
[color=blue]
> Shelly[/color]

dave[color=blue]
>[/color]


Sheldon Glickler
Guest
 
Posts: n/a
#3: Feb 21 '06

re: Closing window



"d" <d@example.com> wrote in message
news:d6IKf.24256$wl.8527@text.news.blueyonder.co.u k...[color=blue]
> "Sheldon Glickler" <sheldonlg@bellsouth.net> wrote in message
> news:6XHKf.18061$UD1.9984@bignews2.bellsouth.net.. .[color=green]
>> Here is a problem I encounter often but haven't solved.
>>
>> In a form I have a submit button. When clicked, I want to do some
>> processing so I check with the isset($_POST['the_button_name']). (I keep
>> all my code above the html code). Now, once I have done that processing,
>> I want the window to disappear. Is it as simple as adding an on_click
>> event to close the window? Will the processing then still take place?[/color]
>
> If the window was not opened with javascript, you might get a warning if
> you try to close it.
>
> The best (only?) way to close it in this situation is to spit out some
> javascript after you process the $_POST:
>
> <script type="text/javascript">
> window.close();
> </script>
>
> and then exit your script. Your window will then close after the
> processing has been done.
>[color=green]
>> Shelly[/color]
>
> dave[/color]

First I tried with simply putting in an onClick. That killed the window,
but didn't do the processing. I then changed the code as you suggested (or
as I think you suggested) and nothing showed up in the window.

If I modified it further and put your suggestion in the <head> section, then
the window doesn't even open.
If I enapsulate it in a function inside the scritpt (in the <head>) and
blindly call that function, I get a stack overflow.

Here is how I modified itas per your post (as I understood it)

<?php
session_start();
if (isset($_POST['editText'])) {
// write this little file to check that the processing is done
$handle = fopen("junk.txt", 'w');
fwrite($handle,"The writing succeeded");
fclose($handle);

// I put it here
<script type="text/javascript">
window.close();
</script>
}
?>
(html leading up to the table stuff)
<table width="600" border="1">
(stuff)
<tr align="center">
<td>&nbsp;
<input name="editText" type="button" value="Submit Changes">
</td></tr>
</table>
(ending html stuff)


Sheldon Glickler
Guest
 
Posts: n/a
#4: Feb 21 '06

re: Closing window


An onclick didn't work. I tried your suggestion of the
<script type="text/javascript">
window.close();
</script>

but where do you place it? If I put it in the html area (in the <head>)
then the window disappears immediately. If I put it in the <?php ?> area at
the top in the the check for the button being clicked, then the window
appears empty.

Here is my code: (cut down a bit). Where do I put the script?

<?php
@session_start();
if (isset($_POST['editText'])) {
//test file to check on success for when window disappearson its own
$handle = fopen("junk.txt", 'w');
fwrite($handle, "Success");
fclose($handle);
}
?>

(html area form/table)
<textarea name="txtShort" cols="80" rows="20"><?php
echo $_SESSION['shortDesc'];?>
</textarea>
<input name="editText" type="submit" value="Submit Changes">
(finishing html stuff)



Iván Sánchez Ortega
Guest
 
Posts: n/a
#5: Feb 21 '06

re: Closing window


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sheldon Glickler wrote:
[color=blue]
> Now, once I have done that processing, I want the window to disappear.[/color]

What window? Think about elinks and wget users.

<matrix>
"Do not try and bend the window. That's impossible. Instead ... only try to
realize the truth."
"What truth?"
"There is no window."
</matrix>


Now, seriously: PHP is intended to output a stream of bytes (typically HTML)
to somewhere (typically a web browser). It is not intended to mess with the
user interface on the client side.

- --
- ----------------------------------
Iván Sánchez Ortega -i-punto-sanchez--arroba-mirame-punto-net

El 67% de las estadísticas son falsas
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD+4db3jcQ2mg3Pc8RAsfTAJ4omrzfla7GWrxp6fuOk6 NNxaJZaACfeiLb
qGgsaBJRR9vGymHI8n1edQQ=
=cIth
-----END PGP SIGNATURE-----
sid.bachtiar@gmail.com
Guest
 
Posts: n/a
#6: Feb 22 '06

re: Closing window


Try this instead:

if (isset($_POST['editText'])) {
// write this little file to check that the processing is done
$handle = fopen("junk.txt", 'w');
fwrite($handle,"The writing succeeded");
fclose($handle);

// ### Try this instead:
echo "<script type=\"text/javascript\">".
"window.close();".
"</script>";
}

Shelly
Guest
 
Posts: n/a
#7: Feb 22 '06

re: Closing window



<sid.bachtiar@gmail.com> wrote in message
news:1140566173.282726.229660@g44g2000cwa.googlegr oups.com...[color=blue]
> Try this instead:
>
> if (isset($_POST['editText'])) {
> // write this little file to check that the processing is done
> $handle = fopen("junk.txt", 'w');
> fwrite($handle,"The writing succeeded");
> fclose($handle);
>
> // ### Try this instead:
> echo "<script type=\"text/javascript\">".
> "window.close();".
> "</script>";
> }
>[/color]

I copied this in and tried it. It worked like a charm. Thanks a lot. Now
for another one.

I open this page to edit the text area. When it is submitted, a session
variable gets set to the contents and now the window disappears. I have a
text field before the link to open this edit page. It is filled with the
first, say, 45 characters of this text field. Is there a way to have this
field updated when the editing page disappears and focus returns to the
original page? (This falls under the "it would be very nice" category).
Currently I have a "refresh button"/

Thanks again. This technique will be very useful for me now and in the
future.

Shelly


feo
Guest
 
Posts: n/a
#8: Feb 22 '06

re: Closing window


Document processing the form:

[...]
Here you proccess the $_POST information.
After processing such information: header ( 'Location:
cierraVentana.html' );
[...]

Code for cierraVentana.html: <script>window.close ();</script>

Might this be useful for you?

feo


"Sheldon Glickler" <sheldonlg@bellsouth.net> escribió en el mensaje
news:6XHKf.18061$UD1.9984@bignews2.bellsouth.net.. .[color=blue]
> Here is a problem I encounter often but haven't solved.
>
> In a form I have a submit button. When clicked, I want to do some
> processing so I check with the isset($_POST['the_button_name']). (I keep
> all my code above the html code). Now, once I have done that processing,
> I want the window to disappear. Is it as simple as adding an on_click
> event to close the window? Will the processing then still take place?
>
> Shelly
>[/color]


sid.bachtiar@gmail.com
Guest
 
Posts: n/a
#9: Mar 15 '06

re: Closing window


Uhmm,

I think it could be a bit too tricky for you, especially after you said
that you "copied this in and tried it." :-\

Let me get this straight
- you have a page with a textarea and a link
- when you click the link, a window is opened
- you do some processing with the poped-up window
- the poped-up window is closed after processing
- you want the original window to show the changes you did in the popup
window?

The bad news is, I'm not really prepared to go into details on this as
it could get tricky for you. Other here who have the time are welcome
to collaborate further.

However, the good news is that I'll leave some clues for you to
research.

First of all, you need to use javascript to open the popup window as a
dialog using javascript function window.showModalDialog (do a research
on google about this javascript function).

Instead of:
<a href="popup_window.php" target="_blank">click me</a>
you'd use:
<a href="javascript: my_function_to_open_window()">click me</a>

Where in my_function_to_open_window() it will be something like:

<script>
function my_function_to_open_window()
{
// open window using window.showModalDialog()

// do stuff to refresh the page, e.g.: document.forms[0].submit()
// which will refresh the page
}
</script>

So, in summary, you do need Javascript to do what you want to do, I
can't think of any other way to handle two windows without javascript
(ofcourse I'm open to ideas).

Kind Regards,

Sid

Closed Thread