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

window.opener not correct when window reopened

P: n/a
I see this problem in IE but not Firefox.

I have a page that opens a second page as a dialog box. If the Dialog
is relaunched from a second instance on the page the Dialog window is
reused, the controls are reinitialized but window.opener still refers to
the original opener. I have simplified code than demonstrated the
problem.

This is the code for the base window which launches the dialog called
Base.html:

<html><head><title>Base</title>
<script language="javascript">

function launch(){

var w = window.open(
"dialog.html",
"Dialog",
"width=400,height=389,scrollbars=no,menubar=no ");
w.focus();

}

function callBack(){
alert("callBack : "+document.getElementById("name").value);
}

</script>
</head>
<body>
<input type="text" id="name"/n>
<input type="button" onClick="launch()" value="Launch" />
</body>
</html>

You see it has a text box, a button and a couple of javascript
functions. When you click the button the Dialog window is launched.

The callBack function is called by the dialog window and throws up an
alert with the contents of the text box. If you type different text
into the text box of both you can then tell which one threw up the alert
box.

Here's the code for Dialog.html:

<html><head><title>Dialog</title>
<script language="javascript">

function linkBack(){

window.opener.callBack();

}

</script>
</head>
<body>
<p>Dialog</p>
<input type="button" onClick="linkBack()" value="Link Back"/>
</body>
</html>

Here we have a button and a javascript function that's called when the
button is clicked. The Javascript function calls through window.opener
to teh callBack function in the opener.

In IE, launch 2 instances of Base.html. In the text box of one of them
type X and click "launch". Then go to the 2nd instance, type Y and
click "Launch". There will only be one instance of the Dialog but click
the "Link Back" button in the Dialog and "callBack : X" will be
displayed.

You could throw some javascript in the onload method of the body tag is
you want to convince yourselfe that the Dialog is actually being
reloaded.

Why isn't the window.opener property updated?

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Lee
Dave said:

I see this problem in IE but not Firefox.

I have a page that opens a second page as a dialog box. If the Dialog
is relaunched from a second instance on the page the Dialog window is
reused, the controls are reinitialized but window.opener still refers to
the original opener. I have simplified code than demonstrated the
problem.
function launch(){

var w = window.open(
"dialog.html",
"Dialog",
"width=400,height=389,scrollbars=no,menubar=no ");
w.focus();

} Why isn't the window.opener property updated?

IE is apparently noticing that you're loading the same URL
in the window, and so is doing nothing. If you modify your
base.html so that you can choose to load a different URL
based on a checkbox state, you'll see that the opener is
updated if the URL is different.

A workaround would be to set w.opener=self in your launch()
function. Put it after the call to focus(), so my suggestion
won't be the line that fails if the window hasn't opened, yet.

Jul 23 '05 #2

P: n/a
Lee
Lee said:

Dave said:

I see this problem in IE but not Firefox.

I have a page that opens a second page as a dialog box. If the Dialog
is relaunched from a second instance on the page the Dialog window is
reused, the controls are reinitialized but window.opener still refers to
the original opener. I have simplified code than demonstrated the
problem.

function launch(){

var w = window.open(
"dialog.html",
"Dialog",
"width=400,height=389,scrollbars=no,menubar=no ");
w.focus();

}

Why isn't the window.opener property updated?

IE is apparently noticing that you're loading the same URL
in the window, and so is doing nothing. If you modify your
base.html so that you can choose to load a different URL
based on a checkbox state, you'll see that the opener is
updated if the URL is different.

A workaround would be to set w.opener=self in your launch()
function. Put it after the call to focus(), so my suggestion
won't be the line that fails if the window hasn't opened, yet.


A more reliable work around might be to simply ensure that the
URL is always unique (unless you're very fast)[untested]:

var w = window.open(
"dialog.html?"+(new Date()).getTime(),
"Dialog",
...

Jul 23 '05 #3

P: n/a
I will try your suggestion but it seems that the page is reloading
because I know that the body's onLoad method will be called.


In article <cb*********@drn.newsguy.com>, RE**************@cox.net
says...
Lee said:

Dave said:

I see this problem in IE but not Firefox.

I have a page that opens a second page as a dialog box. If the Dialog
is relaunched from a second instance on the page the Dialog window is
reused, the controls are reinitialized but window.opener still refers to
the original opener. I have simplified code than demonstrated the
problem.

function launch(){

var w = window.open(
"dialog.html",
"Dialog",
"width=400,height=389,scrollbars=no,menubar=no ");
w.focus();

}

Why isn't the window.opener property updated?

IE is apparently noticing that you're loading the same URL
in the window, and so is doing nothing. If you modify your
base.html so that you can choose to load a different URL
based on a checkbox state, you'll see that the opener is
updated if the URL is different.

A workaround would be to set w.opener=self in your launch()
function. Put it after the call to focus(), so my suggestion
won't be the line that fails if the window hasn't opened, yet.


A more reliable work around might be to simply ensure that the
URL is always unique (unless you're very fast)[untested]:

var w = window.open(
"dialog.html?"+(new Date()).getTime(),
"Dialog",
...

Jul 23 '05 #4

P: n/a
JRS: In article <cb*********@drn.newsguy.com>, seen in
news:comp.lang.javascript, Lee <RE**************@cox.net> posted at Tue,
22 Jun 2004 14:59:30 :

A more reliable work around might be to simply ensure that the
URL is always unique (unless you're very fast)[untested]:

var w = window.open(
"dialog.html?"+(new Date()).getTime(),
"Dialog",
...


In the presence of clock-correcting software, time can repeat. It might
be safer to define globally var Rabbit = 0 ; and to use
"dialog.html?" + Rabbit++ ;

That's not reliable, though, if the same dialog.html is opened from
different local pages.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
Jul 23 '05 #5

P: n/a
In article <cb*********@drn.newsguy.com>, RE**************@cox.net
says...
A workaround would be to set w.opener=self in your launch()
function. Put it after the call to focus(), so my suggestion
won't be the line that fails if the window hasn't opened, yet.


This suggestion seems to have worked both in the sample application I
posted and in teh real application it was derived from.

Thanks a lot.

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.