Click to See Complete Forum and Search --> : Passing variable value between two pages
I need to pass the value of ‘index1’ (set in page1.html) to a variable ‘index2’ in the second page (page2.html) after it has been assigned the value of ‘popupIndex’
So in page1.html
index1 = popupIndex;
And in page2.html
index2 = index1;
So to speak….or just simply still be able to reference ‘index1’var popupIndex = null;
var index1 = null;
function indexOpen()
{
var popupIndex = window.open("photosIndex.html","popupIndex","titlebar=0,minimize=0,width=140,height=180,screenX=200,screenY=300,menubar=no, resizable=no,scrollbars=no,status=no,toolbar=no");
index1 = popupIndex;
}If someone could help please... Thx.....
gil davis
10-16-2003, 05:36 PM
Do you mean you want the window pointer? You can make a pointer to any window that has a name by using window.open() with no URL:
var index1 = window.open("", "popupIndex");
There are other ways to get to the variable if there is a relationship between the windows (parent, child).
Hi gil… Thx for the reply..
‘window pointer’ … Sounds right… I’ll post the complete code and maybe it will explain more…
the main window opens and loads page1.html which displays a photo along with two links, one link to open a pop-up window (photoIndex.html) that has an index of other photos to display, and another link to close the pop-up index window.
I have that part working fine… However, when a link in the pop-up index is clicked and say page2.html is loaded in the main window I loose knowledge the pop-up exists and I can’t close it.
I thought if I could pass a variable from page1.html to page2.html - or page1.html to photoIndex.html and then back to page2.html everything would work as I’m using the variable ‘index1’ in the function within page1.html to close the pop-up…
Page2.html, page3.html etc... are just duplicates of page1.html with just a different image source for each photo.
Hope that isn’t to confusing and I’d appreciate any help…
page1.html (main window)<html><head><title></title>
<script LANGUAGE="JavaScript">
<!--
var popupIndex = null;
var index1 = null;
function indexOpen()
{
var popupIndex = window.open("photosIndex.html","popupIndex","width=140,height=180,screenX=200,screenY=300");
index1 = popupIndex;
}
function indexClose()
{
index1.close();
index1 = null;
}
//-->
</script>
</head>
<body BGCOLOR="#ffffff">
<a href="java script:indexOpen()">Open Photo Index</a><br><br>
<img src="photo1.gif" width="100" height="100" border="0" alt="photo1.gif">
<br><br>
<br><br>
<a href="java script:indexClose()">Close Photo Index</a>
</body></html>
photoIndex.html (pop-up window)<html><head><title></title>
<script>
function openPhoto(photoNum)
{
top.opener.location=photoNum;
}
</script>
</head>
<body BGCOLOR="#ffffff">
<center>
<a href="java script: openPhoto('page1.html');">first photo</a>
<br><br>
<a href="java script: openPhoto('page2.html');">second photo</a>
<br><br>
<a href="java script: openPhoto('page3.html');">third photo</a>
<br><br>
<a href="java script: openPhoto('page4.html');">fourth photo</a>
</center>
</body></html>
gil davis
10-17-2003, 07:18 AM
When you load a new page into "opener", you destroy the relationship, and "opener" no longer exists. If you name the opener window before you open anything, you'll be able to recover a pointer as I already suggested. Add something like this to your pageN.htm files:
window.name = "mainwindow";
Then change the index page to use a name target rather than the opener target.
In pageN.html:
var index1 = null;
window.name = "mainWin";
function indexOpen() {
index1 = window.open("photosIndex.html","popupIndex","width=140,height=180,screenX=200,screenY=300");
}
function indexClose() {
if (index1) {
if (!index1.closed) index1.close();
index1 = null;
}
}
In photosIndex.html:
function openPhoto(photoNum) {
mainWin = window.open(photoNum, "mainWin");
}
As long as "mainWin" is not closed by the user, the index will always open the next file in the same window. It doesn't really matter whether the user closes the index or not, because the mainWin action will always open it again.
You don't need the extra window variable, so I deleted it.