Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close one window from another window.

Status
Not open for further replies.

djunaedwards

Programmer
Sep 7, 2000
15
0
0
US
I program mostly in ColdFusion and don't use JavaScript a lot. Could someone help me with this?

I have a timer window that executes while a query is running. When the window that displays the query results loads, I want to close the timer window. This close needs to occur automatically from the query results window.
The timer window is invoked by
window.open("ka.cfm", "ka",...)
I have tried invoking ka.close() on the query results window, but get js error "'ka' is undefined".

Thanks
 
Create a global javascript variable (inside the <SCRIPT> tags, but outside of any function) called (for example): newWin;

Then, when you do the window.open(...) command, set the return value to newWin. For example:

newWin = window.open(...);

Then, when you want, you can:

newWin.close();

--Dave
 
Thanks for responding.
That does not seem to work in this case.
The sequence of events is:

1) User inputs query on first screen.
2) A submit button submits the form with the query to
the query results page.
3) This submit button also triggers a timer window that
does some other things in the background.
4) When the query results page loads, I need it to
close the timer window.

Thanks,
Djuna
 
In parent (pseudo-code):

Code:
var newWin, timerWindow;
function onClickOfSubmitButton()
{
 newWin = window.open(1st window);
 timerWindow = window.open(2nd window);
}

function closeTimerWindow()
{
 timerWindow.close();
}

In the query results page:

Code:
<body onload='parent.closeTimerWindow();'>
...

Is that what you're after?

--Dave
 
Dave,

That would have worked, but onload was executing before the query had finished. I ended up setting a countdown as the query was outputted to the screen.
When the counter reached 1, I set a session variable (ColdFusion) that was accessible to the counter window which triggered it to close. (this window was periodically refreshing itself)

I really appreciate your help - JavaScript is rather finicky when used with ColdFusion.

Thanks again,
Djuna
 
I've never used ColdFusion, so I am unfamiliar with your exact problem, but I'm glad you figured out a solution!

--Dave
 
Dave,
One final note. My above method worked from a browser activated within HomeSite - the editor that I use for developing, but the timer window still closed way too early with I.E. when used externally. I ended using the body tag idea - I was wrong about the query finishing before the body onload activated - but ColdFusion still refused to cooperate with JavaScript, so I tried a very inelegant, but effective method.
From the query display window, I opened another window of the same name as the timer window using the body onload, which overwrote the timer window. At this point I had active control of the window, and was able to close it.
Thanks again for your help,
Djuna
 
Inelegant, perhaps, but SNEAKY! :)

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top