Writing to iframe issue with Internet Explorer

S

saraiva

Hello.

My web site application has to write syncronosly to an iframe. It puts
in an iframe the directions came from google maps api. This is not an
error from google maps api.
i want the directions to be written in the iframe and in IE the
directions are overwritten, so the user can only read the last one....
In Firefox this works great, the directions are well written in the
iframe and the user is able to read them all, but in Safari and IE
they can't because the directions are all overwritten one by the
others....

My code to write to the iframe is this:

function iframeWrite(val)
{
var testFrame = document.getElementById("step");
var doc = testFrame.contentDocument;
if (doc == undefined || doc == null)
doc = testFrame.contentWindow.document;
doc.open();
doc.write("<span style='color:#000000; font-size:12px; font:Arial,
Helvetica, sans-serif;'>" + val + "</span>\r\n");
}

I only close the iframe writing after i have written all the content i
want on the iframe.....

best regards,
hope you can help
 
T

Thomas 'PointedEars' Lahn

saraiva said:
In Firefox this works great, the directions are well written in the
iframe and the user is able to read them all,

That is a bug. (Bugzilla ID anyone?)
but in Safari and IE they can't because the directions are all overwritten
one by the others....

Works as specified:

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-72161170
My code to write to the iframe is this:

function iframeWrite(val)
{
var testFrame = document.getElementById("step");

if (!testFrame) return false;

or put the rest in a block only executed if testFrame evaluates to `true'.
var doc = testFrame.contentDocument;
if (doc == undefined || doc == null)

This is pointless as due to type conversion either none or both simple
operations result in `true' (although shortcut evaluation prevents the
second one from being considered if the first one is `true'):

if (!doc)
{
doc = testFrame.contentWindow.document;
}

if (doc)
{
doc.open();
doc.write("<span style='color:#000000; font-size:12px; font:Arial,
Helvetica, sans-serif;'>" + val + "</span>\r\n");

Looks awful. Why not write a `style' *element* first and do all the
formatting there? Besides, the generated markup (and probably the
generating one as well) is currently not valid and not accessible:

http://validator.w3.org/
http://www.w3.org/WAI/guid-tech.html
}

I only close the iframe writing after i have written all the content i
want on the iframe.....

Then also open it only once, and another problem goes away ...


PointedEars
 
V

VK

Hello.

My web site application has to write syncronosly to an iframe. It puts
in an iframe the directions came from google maps api. This is not an
error from google maps api.
i want the directions to be written in the iframe and in IE the
directions are overwritten, so the user can only read the last one....
In Firefox this works great, the directions are well written in the
iframe and the user is able to read them all, but in Safari and IE
they can't because the directions are all overwritten one by the
others....

My code to write to the iframe is this:

function iframeWrite(val)
{
var testFrame = document.getElementById("step");
var doc = testFrame.contentDocument;
if (doc == undefined || doc == null)
doc = testFrame.contentWindow.document;
doc.open();
doc.write("<span style='color:#000000; font-size:12px; font:Arial,
Helvetica, sans-serif;'>" + val + "</span>\r\n");

}

I only close the iframe writing after i have written all the content i
want on the iframe.....

It doesn't matter: IE and a number of other browsers automatically
close input stream on exit from the execution context. Firefox keeps
the input stream open until explicit document.close() command. This is
why you see so many dynamic pages in the Web with cursor in the
perpetual waiting mode if viewed in Firefox. Taking into account the
current low culture of the programming such "automatic code cleanup"
maybe not such a bad idea and maybe Firefox shouldn't be so strict. A
disputable matter.
In your case you simply cannot use document.write to keep your
solution cross-browser compatible. If the content indeed arrives by
chunks and you want to display each chunk as soon as ready, use DOM
methods instead to add content to your iframe.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top