473,408 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Close Child Window via Parent using setTimeout

I would like to close a child window I opened from the parent using
setTimout. I have the function below, but it always returns the error
"sendWindow is undefined".

I would appreciate any pointers.
function sendWindow()
{
var sendWin =
window.open('about:blank','sendwindow','width=100, height=100');
setTimeout('sendWin.close()',200);

}

Thank you
Jul 23 '05 #1
3 2384
I meant to write "sendWin is undefined". I apologize for any
confusion.

Jul 23 '05 #2
John Smith wrote:
function sendWindow()
{
var sendWin =
window.open('about:blank','sendwindow','width=100, height=100');
setTimeout('sendWin.close()',200);

}


Statements executed by setTimeout() run in the global execution
context, your variable sendWin is defined in your local function
context only (by using "var" inside the function).

Either you have to make sendWin global ...

var sendWin;
function sendWindow() {
sendWin = window.open(...);
setTimeout("if (sendWin && !senWin.closed) sendWin.close()", 200);
}

.... or you may use a closure, what means keeping sendWin
accessible in an nested function (JS1.2+) ...

function sendWindow() {
var sendWin = window.open(...);
setTimeout(function() {
if (sendWin && !senWin.closed) sendWin.close();
}, 200);
}

ciao, dhgm
Jul 23 '05 #3
On Sat, 2 Apr 2005 14:47:36 +0200, "Dietmar Meier"
<us***************@innoline-systemtechnik.de> wrote:

:John Smith wrote:
:
:> function sendWindow()
:> {
:> var sendWin =
:> window.open('about:blank','sendwindow','width=100, height=100');
:> setTimeout('sendWin.close()',200);
:>
:> }
:
:Statements executed by setTimeout() run in the global execution
:context, your variable sendWin is defined in your local function
:context only (by using "var" inside the function).
:
:Either you have to make sendWin global ...
:
:var sendWin;
:function sendWindow() {
: sendWin = window.open(...);
: setTimeout("if (sendWin && !senWin.closed) sendWin.close()", 200);
:}
:
:... or you may use a closure, what means keeping sendWin
:accessible in an nested function (JS1.2+) ...
:
:function sendWindow() {
: var sendWin = window.open(...);
: setTimeout(function() {
: if (sendWin && !senWin.closed) sendWin.close();
: }, 200);
:}
:
:ciao, dhgm

Thank you! That worked great.

Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Irvin Amoraal | last post by:
Process: I have a form which uploads a file from client to server written in PHP. When the user presses the submit button, I use the "onSubmit" event to execute javascript to open a child window...
1
by: dryer | last post by:
I'm trying to pass some values back and forth between a main page (on https) and a child window (on http) and keep getting 'Access Denied' messages. I know this is a security issue with the...
0
by: Prisy | last post by:
I am working on a web application. When i log out of the parent window i want all the child windows that are open to close. I picked one of the child windows and tried the code shown below to...
1
by: Samy | last post by:
Hi There, I have a child window opened from aspx page using window.open. On the child window, I have a button(New category) which opens a grandchild. I also have a cancel button on the child...
7
by: mg | last post by:
I need to first open WebForm2 from WebForm1 and then close WebForm1 without the end user having to press an OK button before the close can occur. For example, possibly ...
2
by: sanscrimson | last post by:
Hi! I just want to ask if it possible to call functions in parent window if the child window is created. Below is sample:...
2
by: javanet | last post by:
Hi all, 1) i opened a parent window. 2) then i opend a child window thruogh this parent window. Now i want to close child window before closing the parend window means my clients can not be...
2
by: gsuns82 | last post by:
hi all, I got to reload parent window from its child window,i used the folloeing code opener.location.reload(); self.close(); in child window. Parent window gets...
5
Frinavale
by: Frinavale | last post by:
This might be a very newbieish question but here it goes. I have a control that "pops out" when the user clicks a link. The control is a <div> element with some stuff in it that is...
2
by: Melanie Cohl | last post by:
I would like to close a child window I opened from the parent using setTimout. I have tried these functions below, i succeed to open the window, but failed in closing it using the setTimeout...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.