New URL on the same window

R

Renuka

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">
function PageRedirection()
{
if(!opener)
{
//document.url("Search.aspx");
//location.replace("Search.aspx");
window.location.href = "Search.aspx";
}
else
{
window.close();
}
}
</script>
Can someone help???
Thanks in advance
 
L

Lee

Renuka said:
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">
function PageRedirection()
{
if(!opener)
{
//document.url("Search.aspx");
//location.replace("Search.aspx");
window.location.href = "Search.aspx";
}
else
{
window.close();
}
}
</script>
Can someone help???

What does "does not work" mean, precisely?
With the <script> tag corrected to:
<script type="text/javascript">
it works fine for me in several browsers.
 
R

Renuka Srivastava

The new URL which should open on th esame window does not work , to be
precise this exact line does not work:


window.location.href = "Search.aspx";

What works is the window.close() method.

Thanks
Renuka
 
L

Lee

Renuka Srivastava said:
The new URL which should open on th esame window does not work , to be
precise this exact line does not work:


window.location.href = "Search.aspx";

What works is the window.close() method.

That still doesn't tell me what you mean by "does not work".
Are there any error messages? Does it do nothing at all, or
does it seem to do the wrong thing?
 
R

Renuka Srivastava

I have a Confirmation.aspx page with an "OK" button. Once that button is
clicked it instantiates the javascript function on the clientside. If
this Confirmation.aspx has an opener the "OK" button should close the
browser window(which works properly), but when there is no opener the
"OK" button should open a different URL on the same window instead it
remains on the page Confirmation.aspx

window.location.href = "Search.aspx";

Hope I have made myself clear
 
L

Lee

Renuka Srivastava said:
I have a Confirmation.aspx page with an "OK" button. Once that button is
clicked it instantiates the javascript function on the clientside. If
this Confirmation.aspx has an opener the "OK" button should close the
browser window(which works properly), but when there is no opener the
"OK" button should open a different URL on the same window instead it
remains on the page Confirmation.aspx

window.location.href = "Search.aspx";

Hope I have made myself clear

My best guess is that "Search.aspx" is not found.
Try specifying the complete URL.
Your code as written works just fine, if the specified URL exists.
 
M

Michael Winter

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):

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.
 
L

Lee

Michael Winter said:
What you have in your post is reversed, so when window.opener
references a window object, it closes the window rather than
redirecting it.

Why do you assume that this isn't what the OP wants?
If this is not a child window, redirect to the new location.
If this is a child window, close it.
 
M

Michael Winter

Lee wrote on 10 Dec 2003 at Wed, 10 Dec 2003 01:00:42 GMT:
Michael Winter said:

Why do you assume that this isn't what the OP wants? If this is
not a child window, redirect to the new location. If this is a
child window, close it.

Umm, perhaps because the OP said that a child window (i.e.
non-null window.opener) should be redirected, whilst a window with
a null window.opener should be closed.

From the original post:
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.

Mike
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top