Free content for your website or blog
Home About Us Article Writing Most Read Articles Authors Blog Wiki Contact Us
RSS Register Login
Topics
 
Home > Webmasters >

Dynamic Div’s

Date Published: 21st February 2007
Bookmark and Share
Author: fred1923 RSS Views: N/A PRINT ASK ABOUT THIS ARTICLE
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(
) 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. (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:

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:

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:


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.

This article is copyright
Source: http://www.articlealley.com/article_131547_16.html
Bookmark and Share

Related Video

Image resize How To Double Traffic To Your Site In 24 Hours Web Site Promotion - Majon.com YT Hack! Get alerts on new videos without going...
 

Ask a Question About this Article

>> Describe a system for measuring phase changes at one frequency in S band with a dynamic range of 100 dB
>> Is free will an illusion that must be postulated to enable the effective functioning of religion and criminal justice?
>> Are you looking for a RECESSION PROOF BUSINESS OPPORTUNITY?
>> I am not sure how to adequately express all of my ...
Powered by