Renuka wrote on 09 Dec 2003 at Tue, 09 Dec 2003 16:38:22 GMT:
I have a confirmation page with an OK button. If this window has
an opener then this browser window needs to go to another URL or
else the window must close.
Thus I have the following javascript to achieve the above which
does not work:
<script language="jscript">
You must use the type attribute: it is required by the HTML
specification. The language attribute is then usually not needed. The
above should read (assuming you're using JScript, and not
JavaScript):
<script type="text/jscript">
function PageRedirection()
{
if(!opener)
{
//document.url("Search.aspx");
//location.replace("Search.aspx");
window.location.href = "Search.aspx";
}
else
{
window.close();
}
}
</script>
Simple: remove the exclamation mark (!). Think about it...
A call to window.open() opens a new window (child), and sets the
window.opener property of the child to reference the parent's window
object (hope that made sense) [1]. If a window wasn't opened with a
window.open() call, window.opener is undefined or null (depending on
the browser). The former evaluates to true as a boolean, and the
latter as false:
if ( window.opener ) {
// Window opened with window.open()
} else {
// Window opened by some other means
}
What you have in your post is reversed, so when window.opener
references a window object, it closes the window rather than
redirecting it.
On a different note: I would advise that you fully qualify the opener
property. That is, use window.opener, not just opener.
Mike
[1] The first part of that sentence is /very/ important: the
window.opener property is set when window.open() is used to create
the window.
--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")