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!

check if window open

Status
Not open for further replies.

jdulberg

Technical User
Jun 19, 2001
22
CA
I have a link in a remote window that will blur itself and focus the opener window. The problem that I'm running into now is checking from the opener to see if the remote window is open so I can focus it. Here's what I have so far but I'm getting errors.
Code:
var feedbackWin;
if (!feedbackWin) {
   feedbackWin=window.open(url,'feedback',settings);
}
else {
   feedbackWin.focus();
}
Basically what's happening is that the existing feedbackWin is being focused and reloaded instead of just being focused.

There is a form on the child window that will contain data before the user clicks to focus the parent... so I'm trying to keep the data that's in the form rather than just reloading the child window.

Any help is greatly appreciated :)
 
This works for me in IE5.5. What errors are you getting?
Code:
//make sure the variable is outside the function which sets it, otherwise you'll be creating it each time & therefore it won't have a previous value
var feedbackWin;
function doThis() {
if (!feedbackWin) {
   feedbackWin=window.open("test1.htm",'feedback',"");
}
else {
   feedbackWin.focus();
}
}

In test1.htm, I have an alert in the body onload event & it is only firing the first time the window is opened.

Hope this helps,
Jessica
[ponytails2]
 
Well, I guess its not a javascript error per se, it's more of a functional error. Its refreshing an existing child window instead of just focusing it. Here is the code used to open the child

Code:
function openFeedbackWindow(thePage) {
   feedbackWin=window.open(thePage,'feedback',settings)
}

So when this child window loses focus from a link, it will contain content that the user enters into the form. Once the user finishes with the data entry on the parent, the child should re-focus with the old data. That's when I attempt to check to see if the child window exists before focusing. But now it appears that no matter what, it just reloads the child instead of focusing it. If I tried to use the "feedbackWin.closed" method, it errors out that feedbackWin didn't exist.

Its quite a confusing situation. Thank you for your help :)
 
What happens when the user is done entering data on the parent? By that I mean, is a form submitted or does it simply try to set focus to the child window? Hope this helps,
Jessica
[ponytails2]
 
A form is being submitted via php on the parent... when the form success message shows on the parent, the existing child window should focus. If for some reason, the user closed the child window, a new one should open.

Thanks for your time :)

Jason
 
I'm thinking what is happening is...

parent - contains variable feedbackWin
When the parent form is submitted I think it's losing the info stored in feedbackWin, so when it goes to set focus - it can't so it reopens it.

I may be wrong in my description of your setup...

How I've gotten around this in the past...
Code:
------------------------------------------------------
| index      |  main                                 |
| var newWin |  parent.index.newWin = window.open...
------------------------------------------------------

Since the newWin variable is in a frame that doesn't get refreshed, it will keep the correct child window handle.

You can do this by using a hidden frame, instead of an index type frame as shown here...

Hope this helps,
Jessica
[ponytails2]
 
hmm.... so the only way you think to get around this problem is to use a frame?

Jason
 
I'm thinking not (someone please correct me if I'm wrong!). I don't know of any other way to get the handle of the feedback window without storing it someplace static by the parent window.

I saw a couple other threads which say you can get an existing handle by using the window.open() with the url blank, but I keep getting a blank about window...so I don't see how that works. Hope this helps,
Jessica
[ponytails2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top