Newbie... Simple Window close() question

D

DixieGal

I know enough javascript to be dangerous <wink>
I created a link that opens a small popup window.

Now I want my "close window" button to
close the popup, return to the parent window
that opened the popup, and then go to another page.

I can do the close window....
but I am stuck on the return to parent and go to new page...

Any suggestions?
DixieGal

--
 
M

Micky McQuade

Just thinking off the top of my head, why don't you call a function in
your parent window that does those three things.

window.opener.doAllThree(self)

and then in your parent

function doAllThree(objWindow) {
objWindow.close();
self.focus();
document.location.href = 'whatever.htm';
}

This is definitely just thinking. I'm not even sure that you can pass
the reference to the window object like that or not....hopefully it
will get you closer though.

Micky
 
R

Richard

DixieGal said:
I know enough javascript to be dangerous <wink>
I created a link that opens a small popup window.

Now I want my "close window" button to
close the popup, return to the parent window
that opened the popup, and then go to another page.

I can do the close window....
but I am stuck on the return to parent and go to new page...

Any suggestions?
DixieGal

This script uses window.focus, which ensures that the popup will be "on top"
rather than behind the scenes.
You can try adding your window.close() to it and see if this works for you
or not.
It was designed to bring the popup to the front if the visitor did not close
the window and went back to the originating page.


<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
window.open(href, windowname,
'width=600,height=100,left=100,top=200,resizable=yes,scrollbars=yes');
return false;
}
//-->
</SCRIPT>

<A
HREF="popupbasic.html"
onClick="return popup(this, 'notes')">my popup</A>
 
R

Richard Cornford

Richard said:
DixieGal wrote:
This script uses window.focus,

No it doesn't.
which ensures that the popup will be
"on top" rather than behind the scenes.

Where implemented, in the absence of pop-up blocking, and not disabled
by user settings, - window.focus - would do that, but the method does
not do anything if it is never called.
You can try adding your window.close() to it and
see if this works for you or not.

There would be little point in doing that as the effect would not
resemble the desired outcome in any way.
It was designed to bring the popup to the front
if the visitor did not close the window and went
back to the originating page.

If this script was designed with that intention its implementation was
undertaken by a lunatic as the code posted has no relationship to that
proposed design intention.
<SCRIPT TYPE="text/javascript">
<!--

'Hiding' scripts form 'older browsers' with 'HTML comments' is
redundant.
function popup(mylink, windowname)
{
if (! window.focus)return true;

Testing the implementation to determine whether it supports the
window.focus method does not make sense unless the code guarded by the
test actually employs that method. Otherwise the implication is that
this is a test by which the environment's support for other features is
being inferred from the existence of an unrelated method. Testing of
that type is utterly unreliable.

Additionally, source code posted to Usenet should always be formally
indented (as described in the FAQ).
var href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;

Generally, while it might seem that allowing functions to accept
arguments of indeterminate type would result in code that was more
general in its employment, in reality the result is to promote a
disregard for variable type that is dangerous in a loosely typed
language.

The HTML employing this function will only ever pass an object reference
to this function so this branching is not needed, and neither is the
local variable - href -.
window.open(href, windowname,

Calling a method of the window object that is known not to be
implemented in all environments is obviously misguided. The preceding
test on the wiindow.focus method logically should have been a test on
the widnow.open method, as that is the environment feature that is
actually used by the code.
'width=600,height=100,left=100,top=200,resizable=yes,scrollbars=yes');

It is almost never a good idea to actively position a newly opened
window as the location in which that window opened may have no
relationship to the existing browser window.
return false;

Returning false at this point will cancel the navigation specified in
the HREF of the A element. However, at this point it has not been
determined whether the window opening attempt has been successful. in
the event that the window opening attempt failed (or that the new window
will subsequently be closed by an external pop-up blocker) then this
code should return true so that the browser can fall-back to the HTML
link.
}
//-->
</SCRIPT>

<A
HREF="popupbasic.html"
onClick="return popup(this, 'notes')">my popup</A>

On the whole, inadequate code that bares no apparent relationship to the
OP's question. If you have nothing better to offer you probably should
keep it to yourself.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top