471,066 Members | 1,007 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Creating IFRAMEs in Opera

[Also asked in a private Opera newsgroup.]

In a javascript-heavy page, an iframe is created to hold information
from a secondary server CGI process, and the resulting data (in the
iframe) is used to rewrite some content in the main page. To do this
transparently, the iframe is created with style="display: none".

This scheme works great in IE and Mozilla; but Opera apparently doesn't
load the frame, for some reason. We've seen this behavior using this code
and the Javascript shell at http://www.squarefree.com/shell/shell.html
(a great resource):

1 ifr = document.createElement('iframe');
2 ifr.style.display = 'none';
3 ifr.height = 500;
4 ifr.width = 500;
5 ifr.src = 'http://myserver/simpletest.html';
6 document.body.appendChild(ifr);
7 ifr.style.display = '';

(While running this script, I have a telnet session open on the server,
watching Apache's log file: tail -f access_log.)

Lines 1-4: Create the iframe element and set some attributes.
Line 5 : Specify the source document.
This doesn't prompt any server activity. I pause for a
moment.
Line 6 : Attach the iframe to the current document. Using Mozilla
Firefox and Internet Explorer, I see the request on the
Apache log file. Not so when I use Opera.
Line 7 : Reset the "display" CSS attribute. When I use Opera, the
file request happens after this line is executed.

Playing around a bit, we've noticed that Opera *does* request the file
immediately after line 6 for style="position: fixed; visibility: hidden",
rather than "display: none". But this causes the space for the IFRAME to
be rendered (empty) on the page ... not what we want.

Compounding this problem is that writing code that detects this condition
seems difficult, but we don't want to resort to browser sniffing.

Help?

Howard Jess
Jul 23 '05 #1
4 1898


Howard Jess wrote:

In a javascript-heavy page, an iframe is created to hold information
from a secondary server CGI process, and the resulting data (in the
iframe) is used to rewrite some content in the main page. To do this
transparently, the iframe is created with style="display: none".


It is an optimization not to load the iframe when display is none.
Mozilla used to do the same, only when web developers complained that
they wanted to use hidden iframes the way you want to to it (to make
some hidden request to the server) Mozilla changed the behaviour.

As a workaround you can use
<iframe width="0" height="0"
style="visibility: hidden;"
that way as far as I remember Mozilla, IE, and Opera load the iframe's
content.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Martin Honnen wrote:
Howard Jess wrote:

In a javascript-heavy page, an iframe is created to hold information
from a secondary server CGI process, and the resulting data (in the
iframe) is used to rewrite some content in the main page. To do this
transparently, the iframe is created with style="display: none".


It is an optimization not to load the iframe when display is none.
Mozilla used to do the same, only when web developers complained that
they wanted to use hidden iframes the way you want to to it (to make
some hidden request to the server) Mozilla changed the behaviour.

As a workaround you can use
<iframe width="0" height="0"
style="visibility: hidden;"
that way as far as I remember Mozilla, IE, and Opera load the iframe's
content.


Why the operational difference between a 0-pixel invisible frame and a
non-displayed frame? Also, your workaround uses HTML: Opera's behavior
in that case (static HTML on the page) is the same as Mozilla's and IE's:
the frame data is loaded along with other external data for the page. (That
is, pretty much immediately, along with <img src=...> and <script src=...>
data.) It's only when you create the iframe dynamically and append it to
a document element that this behavior (non-loading if display:none) occurs.

My original post was a contrived example. We're trying to build support
routines for general use (in which case we have no say over what the
programmer/designer may write), while preserving identical behavior across
various browsers. Although your workaround suffices (adding "position: fixed"
to the iframe style), it doesn't help in the general case. And begs the
question above: why does Opera not load a non-displayed document, but it
*does* load an invisible one? And, why does it behave differently for
dynamically- and statically-created iframes?
hj

Jul 23 '05 #3


Howard Jess wrote:

My original post was a contrived example. We're trying to build support
routines for general use (in which case we have no say over what the
programmer/designer may write), while preserving identical behavior across
various browsers. Although your workaround suffices (adding "position: fixed"
to the iframe style), it doesn't help in the general case. And begs the
question above: why does Opera not load a non-displayed document, but it
*does* load an invisible one? And, why does it behave differently for
dynamically- and statically-created iframes?


I am not qualified to explain Opera behaviour (well unless there is a
standard Opera is following and IE not for instance but I don't think
the CSS standard is going into detail as to wheter to load an element
with display: none), you will need to ask someone at Opera and I think
you have done that in an Opera newsgroup. It was also suggested there
that you file a bug if you think you have experienced one.

If the workarounds suggested here and in the Opera newsgroup don't help
with your general case you will need to provide more information to
enable anyone to try to help you get the same behaviour with Opera as
with Mozilla or IE.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4
Martin Honnen wrote:
Howard Jess wrote:
My original post was a contrived example. We're trying to build support
routines for general use (in which case we have no say over what the
programmer/designer may write), while preserving identical behavior across
various browsers. Although your workaround suffices (adding "position: fixed"
to the iframe style), it doesn't help in the general case. And begs the
question above: why does Opera not load a non-displayed document, but it
*does* load an invisible one? And, why does it behave differently for
dynamically- and statically-created iframes?


I am not qualified to explain Opera behaviour (well unless there is a
standard Opera is following and IE not for instance but I don't think
the CSS standard is going into detail as to wheter to load an element
with display: none), you will need to ask someone at Opera and I think
you have done that in an Opera newsgroup. It was also suggested there
that you file a bug if you think you have experienced one.


Thanks; as you suggested, I've submitted a bug to Opera. I asked the
question here and on the Opera newsgroup hoping that someone else had
already encountered this behavior and could explain it, and/or suggest
some other (Opera-proprietary, if necessary) way to make it work as it
seems it should.

Regards,

hj

Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Dan Popa | last post: by
8 posts views Thread by Steinar Bang | last post: by
7 posts views Thread by bscofield | last post: by
1 post views Thread by innov8iv | last post: by
6 posts views Thread by adnanx82 | last post: by
16 posts views Thread by Mcginkel | last post: by
5 posts views Thread by luckydenis2007 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.