Beruflich Dokumente
Kultur Dokumente
Created 2/16/2003
Dynamic HTML
As discussed earlier DHTML is the combination of 3 browser technologies to render a dynamic browser experience
HTML for content Cascading Style Sheets for general presentation Javascript to enable dynamic presentation
In reality it is tapping into the richness of the browsers Document Object Model (DOM) using HTML, CSS and Javascript that is the key to a highly dynamic browser experience
Browser DOM
Dynamic HTML
With Dynamic HTML the emphasis is on making the browser provide a richer viewing experience through effects like
Animation Filters Transitions
This is done by applying properties and methods of the Browsers Document Object Model (DOM) This is usually done through Javascript, but it can also be done by any scripting language supported by the browser, such as VB-Script
CSS-P Position
tag {position: absolute|relative|fixed|static; left: value; top: value}
left: position in relative or absolute units from left edge top: position in relative or absolute units from top edge absolute: position from top left corner of parent object relative: position in relation to where the browser would place it by default fixed: will not scroll static: this happens by default. The browser determines where to position an object based on natural flow
CSS-P Examples
Absolute:
<div id=1 style="position: absolute; left:100; top:100"> <h1>position: absolute; left:100; top:100</h1> </div>
Relative:
<div id=1 style="position: relative; left:2cm; top:0cm; border-style:dashed"> <h1>position: relative; left:2cm; top:0cm</h1> </div>
Syntax:
tag {zindex: <number> | auto}
number: any integer, positive, negative or zero auto: browser determines (default)
CSS-P z-index
Layering Example
Appears second
Appears first
<div id=1" style="position: absolute; left:100; top:100; background:pink; z-index:3"> <h1>z-index:3</h1> </div> <div id=2" style="position: absolute; left:50; top:50; background:silver; z-index:2"> <p><b>z-index:2</b> The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</p> </div> <div id=3" style="position: absolute; left:150; top:150; background:limegreen; z-index:1"> <h2><b>z-index:1</b> The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog. The quick brown fox jumped over the lazy dog.</h2> </div>
Appears last
CSS-P visibility
Syntax:
tag {visibility: visible | inherit | hidden}
visible: item must be visible inherit: depends on the visibility of parent object
ex: if a <div> is hidden, all tags in the <div> are hidden this is the default
Example:
<p style="visibility:hidden>This text is hidden</p>
CSS-P display:none
Used in conjunction with visibility:hidden Informs the browser to hide all space in the browser window needed for the object. Example:
<p style="visibility:hidden; display:none">An invisible and hidden object</p>
CSS-P Visibility
CSS-P overflow
Specifies how to handle text overflow Syntax:
tag {overflow: visible | hidden | scroll | auto}
visible - increases size to display all the text hidden - text outside of specified height and width is not displayed scroll - adds vertical and horizontal scroll bars, even if unneeded auto - adds vertical and horizontal scroll bars only if needed
CSS-P overflow
Example:
<img src="steve.pg.jpg" style="position: absolute; left:0; top:500; clip: rect(125,414,399,210)" />
Browser Detection
Use navigator.appName
Typically returns Netscapeor Microsoft Internet Explorer
Ex:
document.write("<p>navigator.appName = "+navigator.appName+"<p>");
Full Version:
partFloat(navigator.appVersion)
parseFloat looks through a text string and returns the first floating number it can find, if any.
if (document.all)
Since IE supports the all collection, it should be IE 4.x or greater compatible DOM Some browsers can fake out the browser type, e.g. Opera
if (!(document.all))
Probably Mozilla/Netscape 6+ or a W3C compliant DOM
Cross-Browser Code
Place this code in <head> before functions or in .js file
var isW3C = false; var isIE = false; if (!(document.all)) isW3C=true; /* standard compliant DOM, probably */ if (document.all) isIE=true;
Above code is not foolproof. There are lots of browsers out there but if you can live not supporting a small number of Netscape 4.x and other odd browsers this may be good enough Reference inNS and isIE as needed:
Ex:
if (isW3C) <code specifically for W3C Standard DOM>
DOM Problems
Each browser may extend or modify recommended ways of implementing a browser DOM
Internet Explorer is rife with features like filters and transitions that are unique but limit accessibility of the page to other browsers Other browsers, have similar problems The W3C has come up with a standard DOM that all browsers should implement
See http://www.w3.org/DOM/
Mozilla/Netscape: Usually turned on by default if you use validated XHMTL. Otherwise you may be placed into Quirk mode.
What to do now
W3C DOM standards will be widely adapted by all browser manufacturers over time
The problem right now is supporting older browsers, i.e. IE 5 or less, Netscape 4.
Recommendation: write to W3C standard DOM if possible. In time browsers will catch up If you must support older browsers you have options:
Consider using Flash & Shockwave technologies for dynamic presentation See if it is possible to standardize on a particular browser, such as IE 5 Write complex cross platform code as a last resort
W3C DOM-1
Document Object Model Level 1 It gives the scripting language easy access to the structure, content, and presentation of a document which is written in such languages as HTML and CSS. Compatible with future improvements in technology Allows any scripting language to interact with whatever languages are being used in the document
Typically Javascript is the interface
W3C DOM-1
Provides a standard set of objects for representing HTML and XML documents
Typically HTML objects are used, but XML documents will be more frequently used in the future
Two parts:
Core
Provides a low-level set of fundamental interfaces that can represent any structured document Defines extended interfaces for representing an XML document
HTML
Interfaces with Core Level 1 section to provide a more convenient view of an HTML document
W3C DOM-2
Consists of Core, Events, Style, Traversal and Range, and Views specifications. All build on top of DOM-1 Core Core:
Consists of interfaces to create and manipulate the structure and contents of a document Contains specialized interfaces dedicated to XML
Events: gives to programs and scripts a generic event system Style: allows programs and scripts to dynamically access and update the content and of style sheets documents
W3C DOM-2
Traversal and Range: Allow programs and scripts to dynamically traverse and identify a range of content in a document. Views: allows programs and scripts to dynamically access and update the content of a representation of a document
document.getElementsByTagId
If you know the unique ID attribute to the tag, jump to it directly. Ex:
<p align="right">This is a <b id="hereweare">paragraph</b></p> var x = document.getElementById('hereweare');
Use the common setAttribute method for any DOM object. Example:
node = document.getElementById('hereweare); node.setAttribute('align',val);
You can either create an element or add an attribute to an element Creating an element example:
var x = document.createElement('HR'); document.getElementById('inserthrhere').appendChild(x);