Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

html change frame content

Status
Not open for further replies.

TooNew

Programmer
Aug 29, 2003
23
US
Embarrassed to say I spent about five hours trying to do this and searching for a solution.

I have a generic frameset called “group.htm” with a frame called “mainFrame”. I have a number of htm files with content I want to load into “mainframe” as needed, based on a “getURL” action script command from a button in a flash swf file.

Since I can’t put together a dynamic solution, I have set up a separate frameset for each different htm file with “mainFrame” = to the individual htm’s.

This works but it doesn't make sense to have all the separate framesets that are identical except for the content of “mainFrame”.

I just can’t find the syntax to access and change “mainFrame” in the window created by a function to window.open(“group.htm” ….) executed by the “onload” event.

Developers have to be doing this all the time!
 
Not sure understand the question.

>the window created by a function to window.open(“group.htm” ….)

To prepare for the complete functionality, define a global variable owin say. Then open the frameset by the usual window.open.
[tt]
<script language="javascript">
[blue]var owin;[/blue]
function doit() {
owin=window.open("group.htm");
}
//...
</script>
[/tt]
>...a generic frameset called “group.htm” with a frame called “mainFrame”...
>...I just can’t find the syntax to access and change “mainFrame” in the window created by a function to window.open(“group.htm” ….)...

This is how you can access the individual frame, in particular a named frame "mainFrame".
[tt]
function seturl(sname,surl) {
if([blue]owin[/blue]) {
owin.frames[sname].location=surl;
} else {
alert("Cannot find the frameset window, either it is closed or it has not been launched.");
}
}
[/tt]
The mainFrame can also be accessed by index number of it in the frameset. The above is by name defined in the frameset.

- tsuji
 
Thank you ever so much!
I was using ( ) instead of [ ] in the following code.
myWin.frames["mainFrame"].location=newpage;

Works just as I knew it had to.

Thanks again.
 
tsuji, again thanks for the help.

I find that the "seturl" function dosen't always seem to execute. To try to debug this, I put an "alert" statement between the "doit" function and the "seturl" function and the "seturl" function does executes every time when closing the alert message box. I also tried placing the "seturl" function within a "setTimeout" function and this worked better, but still not consistantly.

function doit(loadSet) {
myWin=window.open(loadSet);
setTimeout("seturl('cemeteryPrices.htm',
'cemeteryPricesNav.htm')",1000);
}

function seturl(setpage,setnav){
if(myWin) {
myWin.frames["mainFrame"].location=setpage;
myWin.frames["topFrame1"].location=setnav;
} else {
alert("Cannot find the frameset window, either it is closed or it has not been launched.");
}
}

<body onLoad="javascript:doit('cemeteryFrameSet.htm');">
 
TooNew, even though adding a protocol javascript: to the onload handler is not very appealling, but should not result in any adverse effect here. I cannot reproduce your observation from simple pages. Take the "javascript:" out and try again? There are issues related to cross-domain security and pages resisting to be loaded in frame setting. But for pages of your own domain and with contents you have full control, I cannot see an obvious reason for inconsistency, though timing may be a legitimate concern.
- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top