| re: Passing values from a function generated html.
In article <4104A9CE.3462663E@blabla.com>,
cirillo_curiosone <cirillo_curiosone@blabla.com> wrote:
[color=blue]
> Hi,
>
> i'm new to javascript. I started studing it on the web few weeks ago,
> but still haven't been able to solve one big problem: HOT TO PASS VALUES
> FROM A SCRIPT VARIABLE TO A CHILD HTML GENERATED BY FUNCTION.
>[/color]
....[color=blue]
> Thanks a lot in advance.[/color]
I believe these HTML files show one method of passing a variable to a
child html file.
The line:
alert("from parent var picture1 =" + parent.frame1);
shows how you can access a variable in the parent file.
What I do in frame1.html is to generalize the code so all the child html
files can be the same. I use the file name of the html file to look for
a variable in the parent. I assume all the file names will be
different.
I tested this in Netscape 7.1 on MacOS 10.2.6.
Here is frames.html which is the parent.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Frames Layout</title>
<SCRIPT type="text/javascript">
var frame1 = "picture 1";
</script>
</head>
<frameset rows="60%,*" cols="65%,20%,*">
<frame src="frame1.html">
<frame src="frame2.html">
<frame src="frame3.html" name="fill_me">
<frame scrolling=yes src="frame4.html">
<frame src="frame5.html">
<frame src="frame6.html" id="test">
<noframes>
Sorry, this document can be viewed only with a
frames-capable browser.
<a href="frame1.html">Take this link</a>
to the first HTML documetn in the set.
</noframeset>
</frameset>
</html>
Here is frame1.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Frame 1</title>
<SCRIPT type="text/javascript">
function nowRun()
{
// Access a variable in the parent's global name space
alert("from parent var picture1 =" + parent.frame1);
// Since we want all the children to have the same code, we
// base the variable access off of the name of the html file.
alert("working with document.url of " + document.URL);
var lastLoc = document.URL.lastIndexOf('/');
alert("begin = " + lastLoc);
if (lastLoc > 0 )
{
var myName = document.URL.substring(lastLoc+1,document.URL.leng th);
alert("myName = " + myName);
var beginLoc = myName.indexOf('.');
alert("beginLoc = " + beginLoc);
if (beginLoc > 0 )
{
var myName = myName.substring(0,beginLoc);
// We name have the variable name.
alert("myName = " + myName);
var localCopy = parent.window[myName];
alert("localCopy = " + localCopy);
}
}
}
</script>
</head>
<body onload="nowRun();">
<p>This is frame 1.</p>
</body>
</html>
Here is frame6.html all the other frame documents are similar.
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Frame 6</title>
</head>
<body>
<p>This is frame 6.</p>
</body>
</html>
Robert |