Sign in to follow this  

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

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
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);
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this