473,408 Members | 1,857 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,408 software developers and data experts.

Passing a JavaScript variable/object reference from one page to another?...

Greetings all...

Here's a description of the problem that I'm trying to solve:

- I have a Web page from which users can open one or more other
windows.
- From that web page, the user can then select another part of the
application thereby loading a different page into the original browser
window (from which one or more "child" windows may have been opened).
- When the user logs out of the application, regardless of whether
they are on the page on which they started (in the original window),
or they are in another part of the application, we need to be able to
close all the windows that the user opened from the original window.

We're using IE 6.0...

My problem is that I can't find a way to pass the object that points
to a window that was opened on one page into another page...

For example:

- I start out on a.html
- I open a window... My code looks something like this:

var myWindow = window.open(...

- In the original browser window (which is currently displaying
a.html) I click a link that takes me to b.html
- In b.html I may need to close myWindow, but I don't have a reference
to it, so I can't call myWindow.close()

Is there any way to pass the myWindow object into b.html (or to store
it in some "global" area from which it can be accessed by any page)?
Either that, or am I missing something far more obvious?

I've started thinking about a number of solutions to this problem, but
none of them are anywhere near elegant...

Any suggestions would be greatly appreciated...

Cheers...

Dave Bruzzone
Jul 20 '05 #1
2 18134
db*******@attbi.com (Davide Bruzzone) wrote in message news:<7f**************************@posting.google. com>...
Greetings all...

Here's a description of the problem that I'm trying to solve:

- I have a Web page from which users can open one or more other
windows.
- From that web page, the user can then select another part of the
application thereby loading a different page into the original browser
window (from which one or more "child" windows may have been opened).
- When the user logs out of the application, regardless of whether
they are on the page on which they started (in the original window),
or they are in another part of the application, we need to be able to
close all the windows that the user opened from the original window.

We're using IE 6.0...

My problem is that I can't find a way to pass the object that points
to a window that was opened on one page into another page...

For example:

- I start out on a.html
- I open a window... My code looks something like this:

var myWindow = window.open(...

- In the original browser window (which is currently displaying
a.html) I click a link that takes me to b.html
- In b.html I may need to close myWindow, but I don't have a reference
to it, so I can't call myWindow.close()

Is there any way to pass the myWindow object into b.html (or to store
it in some "global" area from which it can be accessed by any page)?
Either that, or am I missing something far more obvious?

I've started thinking about a number of solutions to this problem, but
none of them are anywhere near elegant...

Any suggestions would be greatly appreciated...

Cheers...

Dave Bruzzone

I'm no expert, but my quick test seems to suggest that user defined
properties of the window become undefined when the document changes.
However, the built-in properties do not. So, say the original window
document source looked like

<script type='text/javascript'>
function openIt(){
opener = open('child.htm','child', 'height=200,width=200');
}
</script>
<title>A</title>
<a href='b.htm'>b</a>
<br>
<button onclick='openIt();'>openIt()</button>

And the child window document:

<title>Child</title>
Child window

And the second document:

<script type='text/javascript'>
function closeIt(){
opener.close();
}
</script>
<title>B</title>
<button onclick='closeIt();'>closeIt()</button>

My test (IE6) shows that the value of the opener property survives the
document change, so the closeIt() function created by the second
document closes the child window.

As I said, I'm strictly a dabbler, so FWIW.
Jul 20 '05 #2
gd*******@hotmail.com (Greg) wrote in message news:<a8**************************@posting.google. com>...
I'm no expert, but my quick test seems to suggest that user defined
properties of the window become undefined when the document changes.
However, the built-in properties do not. So, say the original window
document source looked like

<script type='text/javascript'>
function openIt(){
opener = open('child.htm','child', 'height=200,width=200');
}
</script>
<title>A</title>
<a href='b.htm'>b</a>
<br>
<button onclick='openIt();'>openIt()</button>

And the child window document:

<title>Child</title>
Child window

And the second document:

<script type='text/javascript'>
function closeIt(){
opener.close();
}
</script>
<title>B</title>
<button onclick='closeIt();'>closeIt()</button>

My test (IE6) shows that the value of the opener property survives the
document change, so the closeIt() function created by the second
document closes the child window.

As I said, I'm strictly a dabbler, so FWIW.


That's exactly what I was looking for! Thank you!

Dave
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonas Daunoravicius | last post by:
The subject pretty much sums up what I need to do. Here is what I have so far, but still can't figure out how to get it working: <script language="javascript" type="text/javascript"> function...
2
by: sawtooths | last post by:
I have a page, where onload, I populate various boxes with totals via a javascript function. My page itself is in .asp. My question is, how do I take those javascript values that load initially and...
2
by: Geoff Cox | last post by:
Hello, The code below is aimed at passing the date in the yyyyMMdd format from the javascript calendar in an html file to the php in a another file which then searches a MySQL database. For...
2
by: prabu507 | last post by:
hi, can anyone tell me how to pass a javascript value to an asp page without submitting the page ..... requirement: i can do it in ajax but i dont want to use that .... i want to try in...
5
by: nbt725 | last post by:
Dear Sir, Hello ! I want to get the javascript variable in php code in following function. <script language="JavaScript"> function chg_subcatg(cfield,fieldnm) { // For Retrieval of current...
1
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
I am needing help passing a GET variable to a receiving php page. This html page does not contain an forms for submission(POST/GET methods). First I need to parse the URL string using...
2
by: yuva17raj | last post by:
hi i need to write a javascript function in which i need to update the record by passing a javascript variable and i have tried in this format but no solution can any one help me for the following...
1
by: anshusharma | last post by:
hello, i am new to jsp and javascript.i need to pass the value of a variable in javascript to another variable which is there in my jsp file. i am not able to figure iit out how to do this. thanx...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.