damir_kurecic
asked on
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
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
ASKER
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?
If I click on A window I want to B close also.
And where add your code to?
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()
Window A:
var xx;
function openB()
{
xx = window.open("yourpage.htm"
}
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()
ASKER
yes, but I am using the last one, but need also to close if user selects nothing,
thanks
I will try this code
thanks
I will try this code
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 ;-)
So on unfocus you can do this in popup window:
<body onBlur="window.close()">
But I already said that ;-)
That's true, and works great too.
ASKER
where should I put this one
window.onfocus = closeB();
window.onfocus = closeB();
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.
ASKER
zvonko,
where should I put this one
document.body.onclick = new function(){newwindow.close ()};
where should I put this one
document.body.onclick = new function(){newwindow.close
ASKER
zvonko,
where should I put this one
document.body.onclick = new function(){newwindow.close ()};
I really need an answer, it's not a joke!
where should I put this one
document.body.onclick = new function(){newwindow.close
I really need an answer, it's not a joke!
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
window.opener = "_self";
window.Close();
OR
self.opener=this
self.close()