[web] Problem with a control I'm creating.
So, I'm creating a tabbed control from scratch and am having a problem with the javascript (the biggest problem is that I don't know javascript....).
The control uses a hidden IFRAME for communication with the server. When you click on a tab the url of the IFRAME is changed to the URL associated with that tab the next line of code copies the innerHTML from the IFRAME to the tab body div.
The problem is that when I do it like that you don't see the change 'till the next time you click a tab. For example:
Page loads tab A as default
User clicks tab B - no change
User clicks tab B again - Page updates
User clicks tab A - no change
User clicks tab B - tab A gets loaded
In short, it's one update behind. To counteract this I added a timer and have it wait 1/10 of a second before copying the data from the IFRAME to the DIV. In Firefox it *kinda* fixes the problem, but it still happens sometimes, in IE it doesn't fix the problem at all (does timer not work in IE?).
Is there a way to make the URL change of the IFRAME a blocking call and make it not proceed 'till the new data is loaded?
Ok, I *think* I fixed the problem.
Rather than wait a long (1/10th of a second) period of time to update the display I now copy the old innerHTML of the IFRAME, perform the update and set the timer to 1/250th of a second and do this:
Note: Despite my previous problems using a timer in IE this seems to have also fixed the problem there too.
Rather than wait a long (1/10th of a second) period of time to update the display I now copy the old innerHTML of the IFRAME, perform the update and set the timer to 1/250th of a second and do this:
function CopyFrameData(){ //Why this is needed I'm not sure. javascript seems to have a problem with updating the //innerHTML field directly after changing the value of href, so a slight delay was added //to give the IFRAME time to load the new data. if(old_data == window.tab_<?= $container_id; ?>.document.body.innerHTML) setTimeout("CopyFrameData()", 5); else document.getElementById("tab_body").innerHTML = window.tab_<?= $container_id; ?>.document.body.innerHTML;}
Note: Despite my previous problems using a timer in IE this seems to have also fixed the problem there too.
New problem!
I have a feeling that this problem wont be so easy to fix.
So, script elements in the copied innerHTML don't execute....
They execute in the IFRAME, but once they are copied into the DIV the scripts all die.
Aside from totally redesigning is there anything I can do?
Can an entire script block be added to a page dynamically?
I have a feeling that this problem wont be so easy to fix.
So, script elements in the copied innerHTML don't execute....
They execute in the IFRAME, but once they are copied into the DIV the scripts all die.
Aside from totally redesigning is there anything I can do?
Can an entire script block be added to a page dynamically?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement