Search code examples
javascriptinternet-exploreriframewindows-mobile-6.1

Question - Setting dynamic HTML using Javascript to iFrames on Windows Mobile 6.1 - IE Mobile6


(excuse me if this is not the right forum to post - i couldn't find anything related to non-native programming and related to this topic)

I Am trying to set a dynamic HTML into an iFrame on the webpage. I have tried a couple of things but none of them seem to work. I m able to read the innerHTML but can't seem to update it.

// Able to read using 
document.getElementById('iFrameIdentifier').innerHTML;

// On Desktop IE, this code works 
document.getElementById('iFrameId').contentWindow.document.open();
document.getElementById('iFrameId').contentWindow.document.write(dynamicHTML);
document.getElementById('iFrameId').contentWindow.document.close();

Ideally the same function should work as how it works for div's but it says 'Object doesn't support this method or property".

I have also tried document.getElementById('iFrameId').document.body.innerHTML.

This apparently replaces the whole HTML of the page and not just the innerHTML.

I have tried out a couple of things and they didn't work

  • document.getElementById('iFrameId').body.innerHTML
  • document.frames[0].document.body.innerHTML

My purpose is to have a container element which can contain dynamic HTML that's set to it.

I've been using it well till now when I observed that the setting innerHTML on a div is taking increasing amount of time because of the onClicks or other JS methods that are attached to the anchors and images in the dynamic HTML. Appears the JS methods or the HTML is some how not getting cleaned up properly (memory leak?)

Also being discussed - http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26185526.html#a32779090


Solution

  • Okay, I kinda resolved the issues that i was facing earlier and the bigger issue which was setting HTML to an iFrame on IEMobile. But i still have one more PIA which is related to double scollbars - which i am currently looking into. There seems to be more poor souls facing similar problem - if i fix that too. I will post an update here.

    How did i finally write to iFrame on IEMobile? Have 2 divs one to wrap the iFrame and the other to write inside an iFrame.

    document.getElementById('OuterDiv').innerHTML = '';
    document.getElementById('OuterDiv').innerHTML = '<iframe id="iFrameId" src="somefile.html"></iframe>';
    

    This creates an iFrame each time and in the somefile.html on load there is a InnerDiv.innerHTML which doesn't seem to leak the memory.

    In the somefile.html there will be an onLoad method which will fetch the HTML (explained below on how i managed to get it) and do a

    document.getElementById('InnerDiv').innerHTML = dynamicHTML;
    

    How did I manage to pass the HTML between parent and child iFrame As well explained by @bobince earlier, one has to rely on 3rd party service like a cookie or a server to pass around the data between parent and the child iFrame.

    I infact used an ActiveXControl to set and get data from the parent and child iFrame's javascript respectively. I won't recommend doing this if you have to introduce an ActiveX Control just for this. I accidentally already have one which I use to get the Dynamic HTML in the first place.

    If you need any help you can DM me - Twitter @Swaroop

    Thanks @bobince for your help. I am marking this one as an answer because it says what i did to fix the issue.