BBB Online Reliability Seal    
 
Dynamic Div’s
Dynamic Div's - How to put live content into a div on your webpage without using iFrames. Make the div container expand and contract to fit the linked content.
Digg This Article   Del.icio.us

I’ve been trying for some time to come to grips with the concept of dynamically rendering pages so that bits of the content change without doing a refresh or rewrite.

There are a number of approaches to this with the obvious one being php. However a lot of coders find this whole php thing to be a bit intimidating, and want a way to make things happen without going down the road of learning that whole new language.

I started out working with iFrames and this is a brillant way to insert live updates and video and stuff into a page; but there are some frustrating limitations. Like for instance your iFrame stays the same size no matter what you squirt into it! Consider an Amazon aStore: the front page is about 600px high, but the actual shop pages are 1000px or more so either this pops up the dreaded scroll bars in your frame or else you have masses of white space.

I have found a way to make what I call Dynamic Divs - I.E., they expand or contract to fit the content linked to. This means you can have a fixed page with a block(<div>) of optional content that exactly fits the linked page.

It is an interesting hybrid mix of php, html and Javascript, but no coding skills are needed. Just copy’n'paste the code.

You need to name the file with a .php suffix to get the “php includes” to work, but it is basically simple html. The trick is to load the required page into a (not visible) storage div, extract it’s content into a variable with a little JavaScript, then write it into the div with the “document.getElementById(”alayer”).innerHTML” call. This reads the (hidden) file and writes it to the Dynamic Div.

See a demo of the technique here. (http://biznz.net/tutorials/liquiddiv.php)  Roll over the top links to see the Dynamic Div in action

Here are the four elements that make this work.
1. divs to hold the page to be inserted
2. Javascript to read the data
3. OnMouseover code to insert the content.
4. An ID’d div to insert the new content into.

1. The “storage boxes” look like this:
<div id=”bin1" class=”bins”><?php include(’demo1.htm’) ?></div>
They have an ID and they need a style class set to display: none; so they are invisible, and there is a php include to load the file to be stored.

2. The Script to “read” the content into the variable looks like this:
<script language=’JavaScript’>
$con1 = document.getElementById(”bin1").innerHTML;
$con2 = document.getElementById(”bin2").innerHTML;
</script>

The script gets the “innerHTML” content of the Element “bin1" and stores it in the variable $con1, and so on.

3. The content can then be written to the page with an onMouseOver call like this:
onmouseover='document.getElementById(”alayer”).innerHTML=$con1;'

4. A Div (ID=aLayer) to receive the content:
<div id=”alayer” style=”width: 750px; background-color:#ffd; “><?php include(’demo0.htm’); ?></div>

Notes:

This technique works best on pages with plain text or simple html. If you load a page with SSI in it, it will fail, because it is not on the server anymore, thus the script can’t work inside a client side page. An embedded PHP include, for instance, can’t work after it has left the server.

Be aware that what you are doing here is nesting complete web pages inside each other. This can have some quite exciting results - for instance if you have style classes in one page, they may conflict with another.

This trick is ideal to dynamically change text and graphic content inside a box(div), but without doing a page refresh or re-writing the page.




Avg Visitor Rating:       Avg Member Rating:       Rate This Article:
0.0 (out of 5), 0 Votes   
4.0 (out of 5), 1 Vote
  

http://weblog.biznz.net


Member Comments

Your Name: 
Subject: 
Comments: 


HTML tags, including links, are now allowed!


Merchant Hot Tips  [ Privacy Policy ]  
Articles and tips on how to successfully build, market, and promote your business online.

Article Categories
•  Affiliate Marketing
•  Affiliate Programs
•  Banner Advertising
•  Domain Name Registration
•  eBook Marketing
•  Ecommerce Software
•  Ecommerce Solution
•  Ecommerce Strategy
•  Email Marketing
•  Email Newsletters
•  Home Office
•  Internet Business
•  Internet Law
•  Internet Marketing Consultant
•  Link Exchange
•  Link Popularity
•  Marketing Software
•  Merchant Account Service
•  Network Marketing
•  Newsletter Advertising
•  Online Auction
•  Online Business Opportunities
•  Online Business Promotion
•  Online Store
•  Pay Per Click Advertising
•  Press Release
•  Search Engine Marketing
•  Search Engine Optimization
•  Search Engine Sites
•  Search Engine Submission
•  Shopping Cart
•  Small Business Newsletters
•  Small Business Resources
•  Spam Filtering
•  Starting a Small Business
•  Viral Marketing
•  Web Marketing
•  Web Site Design
•  Web Site Hosting
•  Web Site Traffic

Copyright © 1998-2006. AllMerchants LLC. All Rights Reserved.
41749 Mary Kay Drive, Suite 1B, Clinton Township, MI 48038, USA
(800) 878-2072 Phone, (586) 693-1342 Fax

Members: 11,888    Articles: 1,067    Sites: 11,151