Current location: Hot Scripts Forums » General Web Coding » JavaScript » close window on submit


close window on submit

Reply
  #1 (permalink)  
Old 02-20-06, 01:06 PM
lynchm0bx lynchm0bx is offline
Newbie Coder
 
Join Date: Feb 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
close window on submit

I have an asp page that is being spawned by link. This pop-up lists items from a database. it has a button that opens a link in the same window if you want to add to the database. When I attempt to add script to the page to close the window on submit, it fails
if I open a single window from the parent, and call doit() from the onclick , this script works great at submitting the form. It appears that once another page is loaded in the pop-up, it breaks...

<SCRIPT LANGUAGE="JavaScript">
function doit()
{ document.main.submit()
setTimeout('self.close()',1000);
}
</SCRIPT>



any ideas?
thanks
Reply With Quote
  #2 (permalink)  
Old 02-21-06, 02:43 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
I think this script doesn't work because the submit() function reloads the page. When the page is reloaded, all scripts die. The same thing happens if you open a new document in a window containing a script. All scripts exists in the document, not the window. That means no scripts can execute if the document they're on no longer exists.
Maybe you could try this instead:
in doit() (which I assume is in the popup) you call the setTimeout function from the parent instead. That way the code is executed from the parent and not the popup.
Code:
function doit(){
 window.opener.setTimeout('reference_to_popup.close()',2000) // Call this BEFORE you submit the page.
 document.main.submit()
}
I'm not sure that works. Just make sure you store a reference to the popup with var reference_to_popup = window.open('mypage.htm')
Note that reference_to_popup must be a global variable or it won't be accessible from the popop.

Hope that helps.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 02-21-06, 03:02 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Just as an FYI, I don't think you can close a window via javascript if that window wasn't opened by javascript (you'll get a 'close this window?' prompt instead).
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #4 (permalink)  
Old 02-21-06, 03:09 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
True, but since he opens the database listings in a popup, he can also close it without the warning. But not from within the popup if the document is reloading because of being submitted.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Close window script? timmy long HTML/XHTML/XML 18 07-04-08 09:17 AM
New Window with Submit Button phppick JavaScript 0 07-18-05 04:51 AM
How to disable close button in a window cheenu1979 JavaScript 2 03-22-05 01:23 PM
Window close option Help Imad JavaScript 1 02-22-05 05:11 PM
Need script to close after submit and add cookie Randyd JavaScript 1 08-11-04 12:32 PM


All times are GMT -5. The time now is 11:04 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.