• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 253
  • Last Modified:

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
0
damir_kurecic
Asked:
damir_kurecic
  • 5
  • 4
  • 2
  • +1
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 5
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now