RichardE
11-10-2002, 08:06 AM
How can I change a variable in another window in a frameset?
Frameset has three windows -
Header - Displays at top of screen and has a variable mHeading for the page description
Options - Displays options to be displayed in the main window
Main - Where the various option pages are displayed
When I display a page in main I want to set mHeading so it displays the right description at the top of the screen.
How can I change mHeading when the contents of main change?
And where should I define mHeading so it can be reset when pages change?
Thanks in advance!
joh6nn
11-10-2002, 10:41 AM
if you're new to javascript, this is gonna be kinda complicated, so bare with me.
there are a couple of ways that this might be done. one way, would be to fire off some code, every time that a link, that changed the main frame, was clicked. it would be a lot of work to modify that many links ( as i imagine there are a bunch of them ), so that's out of the question. the other way is to have code that fires, every time a page that would be in that frame, loads. that's lots easier, i think, as there are fewer pages than there are links.
so, in order to make our code fire every time the page loads, ( in the easiest possible manner ), we stick the "onLoad" attribute into the body tag of our page, and then tell it what we want to happen, when the page in fact loads.
so:
<BODY onLoad="top.dwim( );">
that tells the browser, to look at the page, that has the frames definitions in it (which is denoted by "top" here ), and fire a function named "dwim", that we defined in that page. so far, so good, right?
ok, now, as i see it, the best way to do this ( and let me know if you disagree, or had something else in mind ), would be to have mHeading defined in each individual page. the reason for this, is that if you need to change a page, or change it's heading, then they're both in the same place; no confusion as to which heading goes with which page. if you keep them separate, then there's the possiblity of mixing up which heading goes with which page.
so, every page has a variable in it named mHeading. an example of that, would be
<script>
var mHeading = "This is the test description for whichever page this is on. Nifty."
</script>
now that we know where our function is ( in the top page ), and where our mHeading is defined, we need to connect the two.
we do that, by telling our function named dwim, that mHeading is going to be in our main frame, and that we want to use it, to change the appropriate whatever it is ( we'll come back to the particulars of this in a moment ) in another frame.
so, here we go:
<script>
function dwim() {
self.frames['Header'].MHEADING_VARIABLE = self.frames['Main'].mHeading;
}
</script>
now, you'll notice that there's a bit that's in bold. the reason for this, is that exactly what that bit is, depends on a couple of things. Which browsers you want this to work in, whether you want to use a form field to display that variable, or whether you want it to show up as just plain old text.
if you want this to show up in a form field, then you can easily do this in pretty much every browser, even NS4, which doesn't like to do anything. you accomplish this, by using the name of the form, that resides in the Header frame, the name of the field you want it to show up in, and doing this:
self.frames['Header'].document.NameOfForm.NameOfTheField.value = self.frames['Main'].mHeading;
if you want to display this as plain text, then you can do this in most new browsers. the relative number of browsers in which you can't do this, is small enough, that you needn't really worry. you figure out where you want the mHeading text to show up, and you put a <SPAN ID="something"></SPAN> there. be sure to replace the "something" in the ID attribute, with whatever you'd like. then, you do this:
self.frames['Header'].document.getElementById("something").innerHTML = self.frames['Main'].mHeading;
don't forget to change the "something" in side the parenthesis, to match the "something" that you put inside the ID attribute in the span. i didn't bold it, to make sure you'd see it.
if you want to make sure that this shows up as plain text, in NS4, you can do that. But it'll be a real pain in the but, and personally, i don't recommend it; it's more trouble than it's worth. i'm sure the people using NS4, will get along just fine without the heading.
let me know if you don't understand, if this doesn't work, or it's not what you were looking for.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.