...

View Full Version : How to recognize a child window



cdc08x
10-15-2005, 01:07 PM
I'm desperatedly trying to find a way to make something like this:
a parent window creates a new window;
when pressing an anchor, the child window blurs;
the the parent window understand this and reload itself to the URI the child window would like to make it load.

I'd like to understand how to make this but I don't find a way to afford this task. Can someone help me please?

cdc08x
10-16-2005, 09:12 AM
It was easier than how I expected!
This works perfectly on Internet Explorer: just activate this from anchors as onclick function:


function parentReload( newHref )
{ var parentWindow=window.opener;
parentWindow.location.assign(newHref);
window.blur();
parentWindow.focus();
}

I publish my (incomplete) solution anyway because another problem came out: why
window.blur() doesn't work on Mozilla Firefox? Is there another solution?

pccode
10-16-2005, 10:22 AM
I'm using firefox version 1.5b2 and the blur command works fine. What version are you using?

Just a thought, but try removing the semicolons from the end of blur() and focus().

cdc08x
10-16-2005, 11:51 AM
My version is 1.0.7 and it doesn't work (neither on NN), even if removing the semicolons...

martin_narg
10-16-2005, 07:27 PM
I'm using firefox version 1.5b2 and the blur command works fine. What version are you using?

Just a thought, but try removing the semicolons from the end of blur() and focus().!!!! Leave them in! It's much much better to create properly formed javascript, delimiting ends of line with semi-colons.

what about this as a cross-browser solution?

function parentReload(newHref){
if(parent && !parent.closed) {
parent.location.href = newHref;
window.blur();
parent.focus();
}
}

m_n

cdc08x
10-16-2005, 11:10 PM
That's the problem: the window.blur() method.
It doesn't work on Mozilla... and I don't really understand why!

martin_narg
10-17-2005, 01:35 AM
window.blur() is a fully supported method of the window object in the Gecko DOM:
http://developer.mozilla.org/en/docs/DOM:window.blur

Potentially it could be that your current initial ordering of windows is slighty skewed? Also, Firefox has options to disable scripts from focusing and blurring windows - you might want to check these option settings on your computer.

m_n

cdc08x
10-17-2005, 09:22 AM
The 'move or resize existing windows' and 'raise or lower windows' options are both checked but it doesn't work anyway...
Strange, isn't it??

Could you suggest me another way to hide the child window, which is not the blur()-call?

Thanx a lot!!

glenngv
10-17-2005, 09:52 AM
The blur should work but it doesn't get executed because the location object does not have assign method. Check the Javascript Console to see this possible error. But you don't need to blur it because if you set focus to the opener window, the current window will lose focus.

function parentReload( newHref )
{
var parentWindow=window.opener;
if (parentWindow && !parentWindow.closed){ //check if opener is still open
parentWindow.location.href = newHref;
parentWindow.focus();
}
}

cdc08x
10-17-2005, 10:09 AM
THanx for having remembered me to check if the opener was closed!!
The problem is that the page changes in the opener, but the focus doesn't shift from the child to the parent window...

glenngv
10-17-2005, 10:28 AM
Is the popup page in the same domain as the opener? Check the Javascript Console for any error.

cdc08x
10-17-2005, 11:47 AM
No error in the js console.
Maybe the problem is the direct call into an anchor?

I mean, that function is directly called so:

<a href="javascript:parentReload(..)" ... >
is this the reason perhaps?

Naaa I don't think so
:)

glenngv
10-17-2005, 12:06 PM
It might be the "Raise or lower windows" setting in the Advanced Javascript Options is unchecked. This is what martin_narg said in his post.

cdc08x
10-17-2005, 12:39 PM
The 'move or resize existing windows' and 'raise or lower windows' are both checked
Gosh....
Thanx a lot for your help I hope I'm not annoying you :o

glenngv
10-19-2005, 08:38 AM
Do you have the page online? If not, would it be possible for you to create a sample page that shows the behavior?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum