views:

632

answers:

5

When you set an html element to have display: none, the content inside that element (e.g. images and flash) wont be loaded by Firefox until the element is set to be displayed. But Internet Explorer dont behave like that. It loads everything inside hidden elements from start.

Is there a way to prevent IE from loading such content without using javascript?

+4  A: 

Don't insert any content into that element? Only load it using ajax when the user makes is visible.

ZippyV
A: 

Here is an example of what ZippyV is talking about (with a twist)... copy and paste the code below into a new file with an HTML extension and run it!

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<h1>This is the title</h1>
<p>This is a paragraph</p>
<div id="hidden-content"></div>
<p>Another paragraph</p>
<input type="button" id="add-content" value="Add Hidden Content" />

<script type="text/javascript">
    $(document).ready(function() {
     $("#add-content").click(
      function() {
       var info = unescape('%53%68%68%68%2E%2E%2E%20%73%65%63%72%65%74%20%69%6E%66%6F%72%6D%61%74%69%6F%6E');
       $("#hidden-content").html(info);
      }
     );
    });
</script>

</body>
</html>

The twist is that the hidden content to be displayed is first escaped (using the Javascript escape() function). Also, you can place the javascript in a separate file!

robnardo
+1  A: 

As my question regarded a solution not using javascript, I'll answer my own question and just say there is no way so far to prevent IE from loading external files that are part of hidden content.

As the other answers suggest it, there are ways to avoid the problem, but not to solve it. So the answer to my specific question is "NO".

GetFree
The reason people aren't giving you a straight answer is because, from your question, it sounds like you're going to be using javascript anyway. So why exactly do you have this requirement that no JS should be used?
Mark
I always try to avoid using javascript. Many of today's web pages are a complete mess because of javascript abuse (which causes frequent browser freezes). Sometimes you just want to know if something is possible or not. If it's not, then you find a workaround. But you should always try the simplest way first.
GetFree
A: 

Actually if you set the visibility to hidden, ie won't load it.

Art
Really? by setting display:none IE downloads images and flash animations but by setting visibility:hidden it wont? I'll have to try that.
GetFree
A: 

display: none should be hiding the element contents from ie as well as any other browsers.

Did you close all the tags?

Gui Andrade
On Firefox it works as expected, but not in IE
GetFree