Dynamic HTML
From Wikipedia, the free encyclopedia
Dynamic HTML or DHTML is a term used for a collection of technologies, used together to create interactive and animated web sites by using a combination of static markup language (such as HTML), a client-side scripting language (such as JavaScript), the presentation definition language (Cascading Style Sheets), and the Document Object Model. It is a kind of dynamic web page.
Though the term "dynamic web page" can refer to any specific web page that is generated differently for each user, load occurrence, or per specific variable values, those pages with this type of "dynamic" content should not be confused for DHTML. Web pages with this type of dynamic content, though still dynamic web pages, are a result of either server-side scripting (such as PHP or Perl), which generates unique content prior to sending the page to the visitor; or as a result of client-side scripting that is run immediately upon page load, before the static page content is visually generated. DHTML, as described above, is a term specifically reserved for those pages which utilize client-side scripting (such as JavaScript) to effect changes in variables of the presentation definition language (such as CSS), which in turn will effect the look and function of otherwise "static" HTML page content, after the page has been fully loaded and during the viewing process. In effect, the dynamic characteristic of DHTML is found in how it acts and functions as each page is being viewed, not in its ability to generate a unique page with each specific page load.
Dynamic HTML is often used to make rollover or drop-down buttons on a web page.
The term has fallen out of use in recent years, as DHTML scripts often tended to not work well between various web browsers. Newer techniques, such as unobtrusive JavaScript coding, have led to similar results, but in an accessible, standards-compliant way.
Some disadvantages of DHTML are that it is difficult to develop and debug due to varying degrees of support among web browsers of the aforementioned technologies and that the variety of screen sizes means the end look can only be fine-tuned on a limited number of browser and screen-size combinations. Development for relatively recent browsers, such as Internet Explorer 5.0+, Netscape 6.0+, and Opera 7.0+, is aided by a shared Document Object Model.
Contents |
[edit] Structure of a web page
Typically a web page using DHTML is set up the following way
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>DHTML example</title> <script type="text/javascript"> function init() { myObj = document.getElementById("navigation"); // .... more code } window.onload=init; </script> </head> <body> <div id="navigation"></div> </body> </html>
Often the JavaScript code is stored in an external file; this is done by linking the file that contains the JavaScript. This is helpful when several pages use the same script:
<script type="text/javascript" src="myjavascript.js"></script>
See also DOM Events
[edit] Example: Displaying an additional block of text
The following code illustrates an often used function. An additional part of a web page will only be displayed if the user requests it. In e-learning, such a function could be used to display additional hints or an answer the student initially should not see.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Test</title> <style type="text/css"> h2 {background-color: lightblue; width: 100%} a {font-size: larger; background-color: goldenrod} a:hover {background-color: gold} #example1 {display: none; margin: 3%; padding: 4%; background-color: limegreen} </style> <script type="text/javascript"> function changeDisplayState (id) { d=document.getElementById("showhide"); e=document.getElementById(id); if (e.style.display == 'none' || e.style.display == "") { e.style.display = 'block'; d.innerHTML = 'Hide example'; } else { e.style.display = 'none'; d.innerHTML = 'Show example'; } } </script> </head> <body> <h2>How to use a DOM function</h2> <div><a id="showhide" href="javascript:changeDisplayState('example1')">Show example</a></div> <div id="example1"> This is the example. (Additional information, which is only displayed on request)... </div> <div>The general text continues...</div> </body> </html>
[edit] See Also
[edit] External links
[edit] Tutorials and Reference
- QuirksMode, a comprehensive site with test examples and instructions on how to write DHTML code which runs on several browsers.
- Introductory DHTML Tutorial for those taking their first steps in DHTML.
- HTML & DHTML Reference on MSDN
[edit] Libraries and Scripts
- DomAPI DHTML Platform A complete development platform for creating high-powered GUI and data-driven web applications.
- Cross-Browser, two cross-browser JavaScript libraries and demos
- DHTML Central, a web site with a DHTML library and several javascript components for menus, trees, and a library for simplifying cross-browser DHTML programming.
- DHTML Demos, DHTML interactive demos and experiments.
- DHTML Goodies, A library of DHTML and Ajax scripts.
- DHTMLSite, A resource on DHTML/AJAX Tutorials and Scripts.
- Dynamic Drive, a collection of free scripts that you can actually try the effect/script online and then cut and paste the script.
- qooxdoo Advanced opensource LGPL JavaScript Framework
- Yahoo! UI Library, a fully featured DHTML library that supports animation, XMLHTTP and graphical interface widgets.
- Yaldex Library, a web site with free JavaScript-DHTML scripts library and multiple javascript programs.
- jQuery a <20K (1.0 compressed) cross-platform resource with plugins, documentation, etc available under GPL+MIT license.
- Microsoft ATLAS a free ASP.NET resource.