Dynamic HTML
8996
225110643
2008-07-11T22:45:46Z
FlaBot
228773
robot Adding: [[eu:DHTML]]
{{Unreferenced|date=September 2007}}
{{Html series}}
'''Dynamic HTML''', or '''DHTML''', is a collection of technologies used together to create interactive and animated [[web site]]s by using a combination of a static [[markup language]] (such as [[HTML]]), a [[client-side scripting]] language (such as [[JavaScript]]), a presentation definition language (such as [[Cascading Style Sheets|CSS]]), and the [[Document Object Model]].
DHTML allows scripting languages to change [[variable]]s in a web page's definition language, which in turn affects the look and function of otherwise "static" HTML page content, ''after'' the page has been fully loaded and during the viewing process. Thus the dynamic characteristic of DHTML is the way it functions while a page is viewed, not in its ability to generate a unique page with each page load.
By contrast, a [[dynamic web page]] is a broader concept — any web page generated differently for each user, load occurrence, or specific variable values. This includes pages created by client side scripting, and ones created by [[server-side scripting]] (such as [[PHP]] or [[Perl]]) where the web server generates content before sending it to the client.
== Uses ==
DHTML is often used to make rollover buttons or drop-down menus on a web page.
A less common use is to create browser based action games. During the late 1990s and early 2000s, a number of games were created using DHTML, but differences between browsers made this difficult: Many techniques had to be implemented in code to enable the games to work on multiple platforms. Recently browsers have been converging towards the web standards, which has made the design of DHTML games more viable. Those games can be played on all major browsers and they can also be ported to Widgets for [[Mac OS X]] and Gadgets for [[Windows Vista]], which are based on DHTML code.
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 ([[DOM Scripting]]), allow similar effects, but in an accessible, standards-compliant way through [[Progressive Enhancement]].
Some disadvantages of DHTML are that it is difficult to develop and [[debug]] due to varying degrees of support among web browsers of the technologies involved, 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|Internet Explorer 5.0+]], [[Firefox|Mozilla Firefox]] 2.0+, and [[Opera (web browser)|Opera]] 7.0+, is aided by a shared Document Object Model. Basic DHTML support was introduced with [[Internet Explorer 4.0]], although there was a basic dynamic system with [[Netscape Navigator|Netscape Navigator 4.0]].
== Structure of a web page ==
{{seealso|DOM events}}
Typically a web page using DHTML is set up the following way:
<source lang="xml">
<!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>
<pre>
Often the 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:
</pre>
<script type="text/javascript" src="myjavascript.js"></script>
</body>
</html>
</source>
In the above code, the blue code represents the DOCUMENT TYPE declaration, which specifies which version of markup code is used to create the website. The red code shows browser detection Javascript, which enables web pages to adjust to browser application standards and requirements.
== 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.
<source lang="xml">
<!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>
</source>
==External links==
* [http://www.quirksmode.org/ QuirksMode], a comprehensive site with test examples and instructions on how to write DHTML code which runs on several browsers.
* [http://www.yourhtmlsource.com/javascript/dhtmlexplained.html Introductory DHTML Tutorial] for those taking their first steps in DHTML.
* [http://msdn2.microsoft.com/en-us/library/ms533050.aspx HTML & DHTML Reference on MSDN]
{{Internet Explorer}}
{{ECMAScript}}
[[Category:HTML]]
[[Category:Internet Explorer]]
[[cs:DHTML]]
[[de:Dynamic HTML]]
[[es:HTML dinámico]]
[[eu:DHTML]]
[[fr:HTML dynamique]]
[[ko:DHTML]]
[[it:DHTML]]
[[he:Dynamic HTML]]
[[nl:Dynamic HTML]]
[[ja:ダイナミックHTML]]
[[km:ឌីណាមិក HTML]]
[[pl:Dynamiczny HTML]]
[[pt:DHTML]]
[[ru:DHTML]]
[[sv:DHTML]]
[[vi:HTML động]]
[[tr:DHTML]]
[[uk:DHTML]]
[[zh:DHTML]]