473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

window.opener not correct when window reopened

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
5 3684
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Scott | last post by:
I'm new to ASP, but I've been programming in VB for several years, and I'm having a few issues with this ASP enhancement I'm working on. I've found ASP to be a lot different than what I'm use to...
3
by: sentinel | last post by:
Hi all, I'm trying to reload a frame from a pop-up, but really cannot figure this out. Within my index.htm file, I make a link to call a pop-up frame with a javascript function that calls the...
1
by: Diana | last post by:
Hi there, I'm having some difficulty in renaming a window object. I'm opening the window in question via a targetted submit: <!-- CODE EXCERPT FROM WINDOW 1 --> <form target="newWin"> ...
1
by: Tony Farrell | last post by:
Hi Everyone - I have a data entry form that allows the user to click a button and have that button popup a list of available values - the code on the popup window uses the name of the form to...
2
by: Robert Nurse | last post by:
Hi All, I'm trying to alter the contents of a drop-down (select) list on the parent window from a child window in IE 6. After opening the child window, I set its opener to reference the parent...
4
by: ...D. | last post by:
OK. I am halfway decent with HTML. Now I want to try javascript for some things that HTML cannot do. I have looked over a tutorial & all. What I want to do is create a button, that when...
19
by: Darren | last post by:
I have a page that opens a popup window and within the window, some databse info is submitted and the window closes. It then refreshes the original window using window.opener.location.reload(). ...
11
by: Dave | last post by:
For some reason, the below lines only work on select machines. All machines are running IE6. IE SP's and OS's vary. When it doesn't work, default.aspx (the page that this code is in) opens and...
9
by: tshad | last post by:
This was posted before but the message got messed up (all NLs were stripped out for some reason). I have 2 labels that hold the name of different images on my .aspx page. <asp:Label ID="Logo"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.