to close opened window(opened as new window) on unFocus

Hellow!

I had a problem with new opened window of staying opened. So I defined new variable like
newwin=window.open....
newwin.focus();
But a new problem occured:
The new window is staying opened regardless of clicking the window.opener. I want to close this new window if I click on a window.opener.

Please help!

Damir
damir_kurecicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

robotman757Commented:
I am not sure what you mean by clicking on a window.opener, but what I do when I want to close a window after I am done using it is add these lines:

window.opener = "_self";
window.Close();

OR

self.opener=this
self.close()
0
damir_kurecicAuthor Commented:
Look, I have opened A window and then open another one window B.
If I click on A window I want to B close also.

And where add your code to?
0
robotman757Commented:
So you are opening window B from window A? When you click on window A, you want B to close. If this is true, then you should open window B by using a variable and then you can close it from widow A's onFocus() event.

Window A:
var xx;
function openB()
{
xx = window.open("yourpage.htm", "winname", settings);
}
function closeB()
{
xx.Close();
}

window.onfocus = closeB();

I have done this once before, but I found that it was easier to close a window from the window itself once it was done being used.

window B:

functions you want done...
before the closing bracket on the last function:

self.opener=this
self.close()
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

damir_kurecicAuthor Commented:
yes, but I am using the last one, but need also to close if user selects nothing,
thanks
I will try this code
0
ZvonkoSystems architectCommented:
the action oposite the focus event is the blur event.
So on unfocus you can do this in popup window:
<body onBlur="window.close()">


But I already said that ;-)
0
robotman757Commented:
That's true, and works great too.
0
damir_kurecicAuthor Commented:
where should I put this one

window.onfocus = closeB();
0
robotman757Commented:
Actually, I made an assumption and am sorry for that. You might find a problem doing that because I did not include any checking to see if the window exists or not. The body.onblur suggestion from zvonko should work better in this case because it does not care what causes the loss of focus, and just works.
0
damir_kurecicAuthor Commented:
zvonko,

where should I put this one

document.body.onclick = new function(){newwindow.close()};
0
damir_kurecicAuthor Commented:
zvonko,

where should I put this one

document.body.onclick = new function(){newwindow.close()};

I really need an answer, it's not a joke!
0
godspropyCommented:
If IE4Plus is ok you can use window.createPopup(); instead of windwo.open(); the popup window is borderless and closes if the opener receives focus. However, the resulting page is not interactive. You can make the entire body a link but you cannot have forms, etc.
0
ZvonkoSystems architectCommented:
The corrected line should be:

document.body.onclick = function(){newwindow.close()};

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.