|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
javascript close problem?
What i am trying to do is using PHP sessions, but for a very simple aspect i am trying to use js.
They open popup1 from parent1, fill out some boxes and then hit submit. at this time i do some stuff with php and the variabels submitted and then I want to close the current window...how do i do this? i tried doing: Code:
<script language=javascript type=text/javascript>\n"; window.close(); </script> all this does is refresh the current window and not submit the values at all.. anyone know what could work?
__________________
"Mankind cannot define memory, yet it defines mankind" |
|
#2
|
|||
|
|||
|
Submit the form and then close the window.
<script language="javascript"> <!-- function submit_form() { document.form.submit() self.close() } //--> </script> Call the function from your submit button. It will submit the form to whatever you have in your form action and then close the window. |
|
#3
|
||||
|
||||
|
That code should work fine to close the current window.
How are you submitting the variables and using the javascript? I would submit the varaibles to the page they go to, verify that that works, then add the: <script language="JavaScript"> window.close() </script> Regards, Dave
__________________
Never sign your code....it leaves you liable! |
|
#4
|
|||
|
|||
|
That will not work. you cannot call submit() then close after words without possibly canceling the submit. The problem is that the submit action is canceled on close just like if you hit the stop button. To get around it, you could wait a certain amount of time before closing, but that has the unwanted outcome of still canceling the submit on someone with a slow connection.
It is common to want to use a popup window to get data from an individual like a dialog box, then want to close that dialog and update the main window with the received data. The best way I have found to do this is to reference a form in the main window from your popup window. You have to transfer th data back to the main window from the opoup, submit the form from the main window and then close the popup. Here is some example code: Code:
/* Main Window */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<a href='javascript: window.open("popup.html", ""); return false;'>Get Name and Address</a>
<form name='hiddenForm'>
<input type='hidden' name='name' value=''>
<input type='hidden' name='address' value=''>
</form>
</body>
</html>
Code:
/* popup window */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language='javascript>
function sendData() {
var par = window.opener;
par.document.hiddenForm.name.value = document.forms[0].name.value;
par.document.hiddenForm.address.value = document.forms[0].address.value;
par.document.hiddenForm.submit();
self.close();
}
</script>
</head>
<body>
<form onSubmit='sendData(); return false;'>
<input type='text' name='name' size=30>
<input type='text' name='address' size=40>
</form>
</body>
</html>
I did not test this code, but I believe it shoudl work as intended. I have done this before and know that it does work. What happens is that you get information from a person simulating a popup dialog, then after they enter the info and press ok, the dialog is dismissed and the main window is updated with the new information. If you were not intending to refresh the main window, this will not work as is. If you dont want to refresh the main window, you need to make a php script that processes the data, then sends output with something like Code:
<html> <head> <script> window.close(); </script> </head> <body> </body> </html> That should close the window even before it displays a blank white page. This way you can be assured of getting all the info before the page is closed. GL |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > javascript close problem? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|