Richard said:
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.
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.