Icontem

Non-javascript support and divs without dimensions

Recommend this page to a friend!

      Fast Page Content Loader  >  Fast Page Content Loader package blog  >  Load Page Content Fas...  >  All threads  >  Non-javascript support and divs...  >  (Un) Subscribe thread alerts  
Subject:Non-javascript support and divs...
Summary:Non-javascript support and divs without dimensions
Messages:4
Author:red indian
Date:2011-03-01 10:50:35
Update:2011-03-01 21:50:59
 

  1. Non-javascript support and divs...   Reply   Report abuse  
red indian - 2011-03-01 10:50:35
Seems interesting, but do you also support non-javascript browsers with the <noscript> option? Maybe you could even fetch the content from those <noscript id="ad"> blocks using the id. Just an idea that popped into my head.

I've have div elements not honoring it's dimensions before. Just add a &nbsp; to it and it will work again. In this case the content is probably always bigger than a space so no worries there. Otherwise you could set font-size to very small or hide overflow.

  2. Re: Non-javascript support and divs...   Reply   Report abuse  
red indian - 2011-03-01 14:16:25 - In reply to message 1 from red indian
Just did a quick test and it works!

You only have to convert < and > to get html back from <noscript> tags.

Demo code:


<html>
<body>

<!-- Container for HTML -->
<noscript id="ad">This is the content when the script is disabled. It also supports <b>html</b> tags.</noscript>

<!-- Div with yellow background to fill with HTML -->
<div id="ad-target" style="background:yellow;"></div>

<script type="text/javascript">

// Get html
var html = document.getElementById('ad').innerHTML;

// Convert < and >
html = html.replace( /&lt;/ig, '<' ).replace( /&gt;/ig, '>' );

// Just for fun to indicate javascript enabled or disabled
html = html.replace( /disabled/, 'enabled' );

// Write the div with yellow background
document.getElementById('ad-target').innerHTML = html;

</script>
</body>
</html>

  3. Re: Non-javascript support and divs...   Reply   Report abuse  
red indian - 2011-03-01 18:42:57 - In reply to message 2 from red indian
Talking to myself here, but just found out that IE does not support reading the contents of <noscript> tags. So this is not a general solution. Too bad.

  4. Re: Non-javascript support and divs...   Reply   Report abuse  
Manuel Lemos - 2011-03-01 21:50:59 - In reply to message 1 from red indian
Right, but it would be great if it worked in all browsers but as you have realized it would not work in IE.

Another idea that I was thinking is to put it inside a div as comments. I am just not sure if it is possible to access comment data in all browsers. I think I saw that somewhere.

As for not honoring the dimensions, I think I have tried putting a a &nbsp; inside before and it did not work.

Maybe it would be better to have some JavaScript to set the width and height properties right after the div. I am just not sure if the div will be ready to resize right away.