SunQuest
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 9th, 2001, 12:28 PM
dkode dkode is offline
PHP/PERL/.NET Coder
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Location: Daytona Beach, Florida
Posts: 36 dkode User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 sec
Reputation Power: 8
Send a message via AIM to dkode
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"

Reply With Quote
  #2  
Old October 9th, 2001, 04:53 PM
bramsey bramsey is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: USA
Posts: 226 bramsey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 40 m 35 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old October 10th, 2001, 02:50 AM
noodles1100's Avatar
noodles1100 noodles1100 is offline
Corporate Stooge
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Aberdeen, Scotland
Posts: 134 noodles1100 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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!

Reply With Quote
  #4  
Old October 16th, 2001, 04:54 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 35 m 19 sec
Reputation Power: 111
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > javascript close problem?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway