By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

New URL on the same window

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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.

Jul 20 '05 #2

P: n/a
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


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

P: n/a
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?

Jul 20 '05 #4

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #5

P: n/a
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.

Jul 20 '05 #6

P: n/a
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")
Jul 20 '05 #7

P: n/a
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.

Jul 20 '05 #8

P: n/a
Lee wrote on 10 Dec 2003 at Wed, 10 Dec 2003 01:00:42 GMT:
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.


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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.