View Full Version : Complicated mess of javascript and frames

05-01-2014, 06:11 PM
i have a large and rather outdated mess on my site, that employs html frameset
and javascript:loadFrames, which allows me to load different html pages in the parts of the frameset with one click.
however, i have recently added a transparent background iframe to the mix, and can't seem to figure out
a way to make the javascript:load frames to target the iframe, particularly since it is on another page. here's the
javascript:loadFrames script. keep in mind, that i currently only have 2 html frame windows in the frameset: menu and content
and then of course, the new iframe.

<!-- Begin
function loadFrames

(frame1,page1,frame2,page2,frame3,page3,frame4,page4) {
// End -->



<a href="javascript:loadFrames( 'menu', '.html',

'content','.html' )"><img src=".jpg" border=0



05-02-2014, 12:28 AM
You can load pages into the two frames in the frameset because they are there. However, the iframe isn't there until the page that has the iframe is in the frame into which it is being loaded and that page is parsed by the browser. Assuming the iframe is on the page loaded into the content frame and is a named iframe one could do:

function loadFrames(frame1,page1,frame2,page2,frame3,page3,frame4,page4) {
parent[frame1].location = page1;
parent[frame2].onload = function(){
parent[frame2].frames[frame3].location = page3;
parent[frame2].onload = function(){};
parent[frame2].location = page2;

But, if there is not always an iframe on the second page, you will have an error in those cases. And if the second page has its own onload function, it will overwrite the one in the above function before it's executed. These issues could be overcome by using version 5 events for the load event and testing for the existence of the iframe before trying to load to it. To do that, replace the above with:

var addEvent = (function(){return window.addEventListener? function(el, ev, f){
el.addEventListener(ev, f, false);
}:window.attachEvent? function(el, ev, f){
el.attachEvent('on' + ev, f);
var removeEvent = (function(){return window.removeEventListener? function(el, ev, f){
el.removeEventListener(ev, f, false);
}:window.detachEvent? function(el, ev, f){
el.detachEvent('on' + ev, f);
function loadFrames(frame1,page1,frame2,page2,frame3,page3,frame4,page4) {
parent.frames[frame1].location = page1;
function loadIframe(){
if(frame3 && page3 && this.frames[frame3]){this.frames[frame3].location = page3;}
removeEvent(this, 'load', loadIframe);
addEvent(parent.frames[frame2], 'load', loadIframe);
parent.frames[frame2].location = page2;

There's a lot that might go wrong with this, but the idea is sound. So, if there are problems they can probably be worked out.

The browser cache may need to be cleared and/or the page refreshed to see changes.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

05-02-2014, 02:45 PM
here it is. it's messy and old school but was the only way i could solve the problems without learning a bunch of new programming languages, and i'm just a little old lady lol it's obviously not done.

05-02-2014, 03:36 PM
Where's the iframe? Where's the code I wrote for you?

05-02-2014, 04:10 PM
i haven't put it in yet, cause you had said it would have to be refreshed, and i was assuming (maybe i'm wrong?) that you meant the player would have to do that. at the time, i hadn't mentioned that it was a game, so i guess i thought you were saying that it would need be buggy and have to be refreshed, to clear cache etc. how would i implement that? leave the other where it is and just add that to the head? i'm a bit confused about how it works.

05-02-2014, 04:25 PM
p.s. how then do i target the iframe in the actual link that targets the iframe?
will this allow me to target the iframe's name even though it's not a part of the frameset? "javascript:loadFrames( 'menu', '.html',

'content','.html' )"

like, would i put 'menu', 'pagewhatever.html','content','anotherwhatever.html','iframe',theiframepage.html' ?

05-02-2014, 04:34 PM
Whenever you make changes to a site, you will have to wait until the user's browser no longer caches the old material before the new material is available. Usually this will not take long. Some servers force this to happen sooner than others. But it cannot start to happen until the change(s) are made. With such a complex setup, bugs can happen. But those can't be fixed until you tell me about them and/or I notice them, which again cannot happen until the change(s) are made. Mostly the caveat about refreshing and clearing the cache is for you looking at the pages after changes. Most users are doing so many other things in the meantime that they will not be holding your pages in cache very long.

One thing that's important with something like this though is to be sure to backup what you have before changing it.

And when you change a game's site, it sometimes cannot be avoided that the game might have to be started over. I don't think that would happen with the changes we've been discussing. But you know the game much better than I do, as well as what the iframe is going to be for, so you would be the better judge of that.

05-02-2014, 04:57 PM
oh i guess i need to tell you what the iframe is for. i wanted it to be the place where the person's choice of avatar + its modifications, would appear as 3rd person perspective at the bottom of the page, like the footer frame is currently doing. then i could make the iframe transparent, have it mesh with the site better, and not have so many problems getting things to match up. having that long footer at the bottom, that was also rather tall, was eating up alot of the game screen, too. only problem i can think of with it is, that it isn't like the html frameset frames, in that it isn't going to sticky to that player's window in the same way as the html frameset frames do, and that's something that may cause problems. i can't just run one html page in the main window and have the html frameset frames fit into it as customized game choices the player has made. otherwise,i have to start messing around with saving data in the browser memory, and that's beyond my abilities. when i read up on how it works, it just sounded like charlie brown's teacher. if'n ya know what i mean. :D

anyway, can i target the iframe from the actual link html now? notice the javascript loadframe html i use to load the frameset frames, requires a certain syntax that is specific to framesets. will it now accept the iframe as one of its html frames?

05-03-2014, 03:40 AM
Reread my first post in this thread. And instead of backing up what you have, keep what you have as it is. Make a separate folder and copy the site there and then experiment in there using the code I've written for you. If after trying it out you are having problems, let me know and I'll have a look at it.

But you're right. You are not going to be able to have a static page in the iframe unless the page holding the iframe never changes. From what you seem to be saying, that's not how you have envisioned this. You might be able to have the static frame take up less room by adding more frames.

05-03-2014, 10:09 AM
i tried it on my desktop and i realized it will create the problem of loss of static retention of the player's choices. i would still end up with having to create 162 different folders each with the same pages repeated with only player specific changes to each page. that's way over the top at this point because there are 9 race choices, each with 2 gender choices, and each with 2 modification choices, and then the results displayed in 2 different locations (the side frame and the footer or iframe), not to mention a third full view loaded into the side frame and a head only view in the side frame. only way to solve it is to keep the footer. i created a thread in the html forum here, to address this particular problem since it is html frameset issue