/    Sign up×
Community /Pin to ProfileBookmark

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

[COLOR=blue]index1 = popupIndex; [/COLOR]

And in page2.html

[COLOR=blue]index2 = index1; [/COLOR]

So to speak….or just simply still be able to reference ‘index1’

[code=php]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;
}[/code]

If someone could help please… Thx…..

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisOct 16.2003 — 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).
Copy linkTweet thisAlerts:
@JK99authorOct 17.2003 — 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…

[B]page1.html (main window)[/B][code=php]<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>[/code]


[B]photoIndex.html (pop-up window)[/B][code=php]<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> [/code]
Copy linkTweet thisAlerts:
@gil_davisOct 17.2003 — 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:
<i>
</i>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:
<i>
</i>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.
×

Success!

Help @JK99 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...