Jump to content
  • Advertisement
Sign in to follow this  
griffenjam_redux

[web] Problem with a control I'm creating.

This topic is 4091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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:


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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Did you try putting the javascript you copy in a function, then calling that function?

Share this post


Link to post
Share on other sites
I'm trying to use a rich text editor control on a tab and it has a compiled javascript module. Once I get to work tomorrow I'll try wrapping it's init function but I don't know...

This is getting a bit beyond my javascript learning.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!