DHTML
DHTML
Overview Cascading Style Sheets Document Object Model Event Model Filters and Transitions Data Binding Cross-Browser Compatibility Links
What is DHTML
Generally, DHTML refers to applications that allow a Web page to change dynamically without requiring information to be passed to/from a web server.
More specifically, DHTML refers to the interaction of HTML, CSS and Scripting language (JavaScript). Crucial component of DHTML is DOM (Document Object Model)
DHTML = HTML + CSS + JavaScript + DOM
To make Web pages interactive. HTML pages have static nature. DHTML provides us with enhanced creative control so we can manipulate any page element at any time. It is the easiest way to make Web pages interactive. It doesnt increase server workload and require special software to support.
To specify font sizes and faces, margin heights and widths, borders and padding, even text decoration.
To create absolutely and relatively positioned content.
CSS
CSS brings powerful layout and design capabilities to DHTML. CSS provides an efficient way to define universal style.
Separation the structure of document from content allows greater manageability and makes changing the style easier.
CSS evolution
CSS1 (W3C Recommendation in Dec. 1996) It describes the CSS language as well as a simple visual formatting model.
CSS2 (May. 1998) It builds on CSS1 and adds support for media-specific style sheets (e.g. printers and aural devices), downloadable fonts, element positioning and tables.
CSS3 (under development) Concentrate on modularization.
Embed a document-wide style in the <head> element of the document. Provide an inline style exactly where the style needs to be applied.
Examples
Definition Rule
H1 { font-size: 24pt; color: green } .dark { font-weight: bold }
Create Style and Grouping Styles (css1.html) Linking external style sheets (imported.html)
DOM is a platform- and language-neutral interface that allow programs and scripts to dynamically access and manipulate the content, structure and style of documents. DOM chooses OMG IDL to provide languageindependent specification of the DOM interfaces and provides language bindings for Java and ECMAScript.
DOM evolution
Some Objects
window document body history location navigator event screen
Some Collections
all anchors applets forms frames images links
Examples
Event Model
DHTML provides full support for keyboard and mouse events on all page elements. Some popular events
ONLOAD ONCLICK ONMOUSEMOVE ONMOUSEOVER ONMOUSEOUT ONFOCUS and ONBLUR ONERROR (for error handling)
Example (onmouseoverout.html)
Use and combine filters to achieve special effects. Create animated visual transitions between Web pages. Modify filters dynamically using DHTML.
Examples
Data Binding
TDC Tabular Data Control Bind a TABLE and other HTML elements to Data Source Objects (DSOs). Sort and filter data directly on the client without involving the server. Filter data to select only records appropriate for a particular application. Navigate backwards and forwards through a database with the Move methods. Example (advancesort.html)
Cross-browser Compatibility
(Cross-platform)
Most popular browsers are Microsofts Internet Explorer (IE) and Netscapes Navigator (NS). Many features of them are common. Both support HTML, CSS, DOM and JavaScript. Most of their features are incompatible.
Cross-browser Compatibility
Features specific to IE 4.0+ VBScript, JScript ActiveX Control Data Binding Filter and Transition OpenType font
Even when NS and IE expose similar objects for scripting, the syntax is not always the same.
Format of references to elements properties and methods differs between IE 4.0 and NS 4.0. Example: Position an object (obj) at a specific pixel coordinate(x,y). IE 4.0 NS 4.0 obj.pixelLeft(x); obj.moveTo(x, y) obj.pixelTop(y);
Cross-browser Strategies
Include the contents of the style sheet inside a comment (<!-- ... -->) so that browsers that do not recognize the <STYLE> element will ignore it. Create and redirect browser to specific pages using browser detection. Design for common denominator. Custom APIs. Create some JavaScript library for different browsers loading. Building DHTML standard is on the way!
Browser Detection
<!-- Using the navigator object -->
<SCRIPT LANGUAGE = "JavaScript"> function start() { if ( navigator.appName == "Microsoft Internet Explorer" ) { if ( navigator.appVersion.substring( 1, 0 ) >= "4" ) document.location = "newIEversion.html"; else document.location = "oldIEversion.html"; } else document.location = "NSversion.html"; } </SCRIPT>
Links
Thanks!