main | computers| links
DHTML notes
no guarantee
Last change Jan 26, 2005 AD
Index
- Introduction (what is this page about)
- Tips&Tricks, examples - explanations how to do
some nice tricks
- browser-specific notes
- General notes (not browser-specific)
- Quick reference.
- Glossary - explanation of some terms that I use
here
- DHTML demo - a prototype written in DHTML, the
code is a bit 'hacked' (written 'on fly'), but it shows what tricky
things you can do.
- Dynamic Tree Menu generated from
an UL
- Testing & Debugging (with Mozilla)
- display generated HTML etc.
- Various notes (CSS:Position and Disply
etc.)
- BookmarkLets of my own
- Links to useful sites (cross-browser, Netscape, Microsoft, w3c, demos, articles, JavaScript, Discussion of Techniques, non-latin1
characters)
This page is devoted to DHTML (under this term I mean HTML, JavaScript and
style sheets) and especially cross-browser dhtml (the one that works at least
under IE and NS). Its intended audience are people who have already
experience with DHTML and its purpose is to make them aware of some common
(or not so common) problems, as well as give them a number of useful links.
I used to play with DHTML too and, as a result, I've discovered some tricks,
created few .js files and started (though not finished) several 'DHTML
projects'. I hope you will find at least some of them useful.
- Initialize events explains how to use
my init_events.js 'library'. The library includes one main function,
initEvents(Element, Event, Handler); after you call it, if the event
Event happens in the element Element (e.g. you mouse over it), the
function Handler is called to handle the event. The page uses alert() in
a very disturbing way, I'm sorry for that (you can change it and send me
a copy ;-).
- Mouse events page describes how to 'apply'
the events onmouseover and onmouseout on any text (tested under IE and
NS)
- Dynlayers - short explanation how to use
the dynlayers.js library, which I use in most of my examples.
- Autodestruction should have simulated what happens if you press the
autodestruction button :-)). It was a nice idea, but I hadn't time to
finish it. Don't get shocked because of the heading and the lisp code - I
needed some text; the button is in the middle.
- GUI - an attemp to build a "graphical
user interface". In the end I was disappointed by the fruitless effort to
make it working in a desirable way, so I abandoned the project. Anyhow
I've done lot of work on it.PS: it can take a while before it's
loaded.
- Add search to your web page using Google
Add search to your web
Add the following form to your page to search with Google for keywords at
site "http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/". Note:
sometimes you must add there more quotes to prevent the default keywords
(/onlinedocs/...) from being misinterpreted.
<FORM method=GET action="http://www.google.com/search" name="google_search"
onsubmit="document.google_search.q.value=document.google_search.q.value+'
/onlinedocs/libstdc++/latest-doxygen site:gcc.gnu.org'"
> <INPUT TYPE=text name=q size=25
maxlength=255 value=""> <INPUT type=submit
name=btnG VALUE="Google" > </FORM>
- you can change block's visibility (hide<->show) only if position
is defined for the block (either relative or absolute). EX: <DIV
ID="div1" STYLE="position:relative;">text</DIV>
- never use "screen" as a name for an object (rather don't use it at
all)
- if you want to write into a block (i.e. change it's inner html), the
block must have absolute position EX: <DIV ID="div1"
STYLE="position:absolute;">text to be dynamically
changed(rewritten)</DIV>
- actually, if you want a block to "exist", you must specify the position
(otherwise NETSCAPE says st. like "object has no properties")
- Statement "myvar = (cond)? expr1 : expr2; " must not be preceded by
"var" ("var myvar = ..." doesn't work)
- When working with quotes inside quotes, be very, very carefull. One
wrong quote may cause much troubles. To have quotes inside quotes, you
can use, like in C, this: \" . EX: alert("String with \" quotes \" inside
"); Show!
- If using nested blocks, their style can't be specified inline. It must
be spec. externally, either as a # (#myid {...}, attached by "id='myid'
") or as a class (.blue {...}, attached by "class='blue' " - no dot
here). Nested blocks:
<div><div>...</div></div>
- you can't have <div> or <span> inside a link (<a>)
(the link doesn't work in such a case)
- NS ignores centering in <div
align="center"></div>. In IE it works. But style DIV
{text-align: center;} helps.
- Do not add an ID to a <script> tag. While it is allowed in
Explorer, adding 'ID' to the tag disables the tag in Netscape 4, so that
the script isn't executed. (The same goes for LINK tags.)
- Setting MEDIA attribute of LINK to anything but screen makes NS to
ignore the tag completly (e.g. MEDIA="screen,all")
- META notes
- Default scripting language: authors should specify the default
scripting language for all scripts in a document by including the
following META declaration in the HEAD: <META
http-equiv="Content-Script-Type" content="type"> where
type is e.g. text/javascript. 'language' attribute is not used
anymore (html 4.1). Then you can use <script> without the need
to specify what scripting language are you using (because you've set
the default)
- redirection: < META http-equiv="Refresh" content="10;
hello.html"> - this causes the browser to load hello.html in
10 seconds.
- difference between visibility and display property: whatever the
visibility is, the element still occupiest the same place. But if
display=none, it occupies no space.
This section mentiones some 'standard' features, that are already implemented
in some of the latest browsers (IE5 and, perhaps, Netscape Gecko)
- If you want change a link when mouse moves over, the easiest way is to
use the :hover class in CSS (Note: it's very important in what place do
you put it wrt :active etc.)
- external .css file: <LINK href="explosion2.css" rel=stylesheet
type=text/css>
- external script file: <SCRIPT SRC="autodes2_aux.js"
LANGUAGE="JavaScript"> alert("This code is executed only if st.goes
wrong.");</SCRIPT>
- NN, NS
- means Netscape; if it's followed by a number, the number is its
version; 'x' is any number.
- IE
- Internet Explorer. Regarding numbers, the same as for NS holds.
- block
- is any 'block element', for instance <div></div>
See the article "Using
Mozilla in Testing and Debugging Web Sites". See "Debugging JavaScript
Using
Venkman".
- Mozilla: Tools->Web development->DOM
inspector
- display dom tree of [generated] html + style, id and classes of
elements, also inspects JavaScript (methods, variables) and CSS
(classes etc. + their def.)
- Display generated HTML (written by JavaScript)
- In browser, select the part of the page you're interested in,
right-clik->View Selection Source
Using Venkman:
- Open the page to debug Mozilla/Netscape browser.
- Tools->Web Development->JavaScript Debugger starts Venkman
The page will be loaded into Venkman: in the view Load Scripts you shall
see the name of the page (e.g. "mypage.html) among others. Click on it
twice to display it in the Source Code view (if opened).
(Change layout of views: left mouse click on the small square in the top
left corner of a view and drag it around; look for a thin black line that
appears on sides of near views - there it will be placed if you drop
it.)
- Start debugging: open the view "Open Windows"
(View->Show/Hide->...). There shall be 1 item: "Navigator Window".
Click on it and you shall see the name of your page. Right-click on it
and select "Set as Evaluation Object"
Now you can check various objects (type e.g. document.images in the
Interactive Session command line)
- Set a breakpoint or hit the Stop button (= Debug->Stop; F4) to stop
at each line.
- Go to the browser window and reload the page (or do anything else to
trigger the script(s)).
- Debug! (Use the buttons Continue, etc.Step over, Step into,and Step out
and breakpoints.)
- It's still a bit buggy so be ready for anything :-) (version
0.9.79).
CSS: Position and Display
Keywords: position (relative x absolute x static x fixed x inherit ),
display (block x none [x inline x inherit x ...])
Position relative: The element does occupy a space
in the normal text flow, i.e. effects layout/formatting
structure (=> elements below it are moved according to its size). The
space is fixed and: A) is not influenced by offset (setting left,
top) of the element thus if you offset it by height/2 down, 1 half of it will
be hidden (covered by the following element); B) is not influenced by
visibility == hidden, i.e. instead of the element you will see an empty
space of its size => you can't use visiility: hidden to hide the element
completely.
Position absolute: The element does not ccupy a space
in the normal text flow, doesn't effect layout at all => A)
If you set top&left the element is above whatever was at that position or
is hidden below it (w.r.t. z axis) and other elements are not influenced by
it at all; B) If you don't set top&left it will be placed at where the
element in the html source is but will not effect the layout of neighbouring
elements.
Position static: as relative but top&left properties are
ignored. Position fixed: as absolute + the element is fixed
w.r.t. to some reference.
To hide an element so that it does't influence layout of other elements we
may use either position:absolute +
visibility:hidden or better display:none. To show
again: display: block (or inline or ...).
Center a box element
"If both 'margin-left' and 'margin-right' are 'auto', their computed
values are equal."
A <LABEL> that fills all the space available
If you click the light-green area (label's background) the radio becomes
checked.
Code of the long label: <label style="display: block;width: 100%"
for="fp3">a full-row label</label>.
Table for page layout
Using tables to layout a page is strongly discouraged. Tables were not
meant for it so user of a special software would get confused etc. Use rather
CSS.
If you indeed want to use table and you want a fixed-size column left and
occupy-the-rest column rigt you've got a problem. You can set td width=150px
but there is no way to say to the other column "occupy all minus 150px". So I
did this which seems to work under IE6 and Mozilla 1.5 (other browsers not
tested):
Here is DIV with width:150px;
|
... after. (<P> inside the div must
have margin:0 for Mozilla sets bottom+top to 1em) |
Instead of DIV, which is somehow troublesome under NS4.x , we could use an
image with width 150px (e.g. 1x150 transparent gif).
- Insert page's url at its beginning - useful befor saving the page so
you know where it have been downloaded from; tested under IE6, Mozilla
Firebird 0.7. Here we go:
<A href='javascript:(function(){var
b,u;b=document.getElementsByTagName("body")[0];
u=document.createTextNode("Saved from "+document.URL);
if(b.hasChildNodes()){b.insertBefore(u,b.firstChild);}else{b.appendChild(u);}})();'>
insert
"saved from"</A>
Content: cross-browser | netscape | microsoft |
w3c | demos | articles | JavaScript | Discussion
of Techniques
- dmoz.org
Internet programming directory (it seems to be good)
- Cross-Browser Libraries etc.
- Netscape
- Microsoft (M$ Workshops)
- W3 Consorcium
- DHTML pages (demos)
- SPAWN
- uses DynDuo facilities
- FreeFall
- quite nice, works in Netscape 4.7
- articles
- JavaScript and CSS
- REFERENCES
---------------------------------------
SELFHTML 8.0 .fr
(2003) - Documentation pour l'établissement de pages Web, d'environ
1900 pages. (Recherche.)
- Netscape: JS guide 1.5/ref.1.5/(Handbook
1.1 - pretty good (examples, references ...) but out of date)
- CSS2+JavaScript
in Examples of use of properties and functions (Window : confirm
() etc.) - great!!!
- JS
Keywords - reference: unofficial, short but with description,
useful
- PRACTICAL PROBLEMS/ANSWERS ------------
- IRT JavaScript
FAQ, great for practical examples of using JavaScript; if you
want to solve a problem look there.
- QuirksMode: CSS &
JavaScript tips&tricks, browser incompatibilities, over 150
pages
- OTHER
-------------------------------------------
- Tutorial
by Juicy Studio: JavaScript
DOM, Validating
Forms, ...
- informIT
reference of JavaScript commands
- .js LIBRARIES -------------------------------------------------
- Form
Validation at developer.apple
- Validate data
type - is it valid number/ integer/email/date?
- Generic
validation script that can check required fields, data type -
integer,date, email
- JavaScript ready-to-use scripts etc. (see Google
dir.)
- Browser
Feature Detection by Netscape - exactly what features your
browser supporst (in DOMn, CSSn ...)
- TOOLS ---------------------
- The JavaScript
Verifier (jslint) checks for common errors; on-line
- ToJS - Converts
html files to JavaScript 'includes' - helpful when space is limited
or code is need in several places
- Bookmarklets
for web development (see also Bookmarklet
Builder and an
article on them)
- RegExp: JS
1.5 Reference, or RegExp: complete
reference (ignore GNU extensions)
- TOOLS
- Non-latin1
characters
- Characters in the Unicode "Latin
Extended-A" block - a list of characters and their utf8
entities
- Searchable Unicode Chart
- type in either a character's code or a character and press
Enter.
Jakub Holy 2002 AD