Beispiel - Datei dhtml.js:
var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false;
if (document.getElementById) {
DHTML = true;
DOM = true;
} else {
if (document.all) {
DHTML = true;
MSIE4 = true;
} else {
if (document.layers) {
DHTML = true;
NS4 = true;
}
}
}
if (window.opera) {
OP = true;
}
function getElement (Mode, Identifier, ElementNumber) {
var Element;
if (DOM) {
if (Mode.toLowerCase() == "id") {
if (typeof document.getElementById(Identifier) == "object") {
Element = document.getElementById(Identifier);
} else {
Element = false;
}
return Element;
}
if (Mode.toLowerCase() == "name") {
var ElementList = document.getElementsByName(Identifier);
if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
Element = ElementList[ElementNumber];
} else {
Element = false;
}
return Element;
}
if (Mode.toLowerCase() == "tagname") {
var ElementList = document.getElementsByTagName(Identifier);
if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
Element = ElementList[ElementNumber];
} else {
Element = false;
}
return Element;
}
return null;
}
if (MSIE4) {
if (Mode.toLowerCase() == "id") {
if (typeof document.all[Identifier] == "object") {
Element = document.all[Identifier];
} else {
Element = false;
}
return Element;
}
if (Mode.toLowerCase() == "tagname") {
if (typeof document.all.tags(Identifier) == "object") {
Element = document.all.tags(Identifier)[ElementNumber];
} else {
Element = false;
}
return Element;
}
if (Mode.toLowerCase() == "name") {
if (typeof document[Identifier] == "object") {
Element = document[Identifier];
} else {
Element = false;
}
return Element;
}
return false;
}
if (NS4) {
if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
if (typeof document[Identifier] == "object") {
Element = document[Identifier];
} else {
Element = false;
}
return Element;
}
if (Mode.toLowerCase() == "index") {
if (typeof document.layers[Identifier] == "object") {
Element = document.layers[Identifier];
} else {
Element = false;
}
return Element;
}
return false;
}
return false;
}
function getContent (Mode, Identifier, ElementNumber) {
var Content;
var Element = getElement(Mode, Identifier, ElementNumber);
if (!Element) {
return false;
}
if (DOM && Element.firstChild) {
if (Element.firstChild.nodeType == 3) {
Content = Element.firstChild.nodeValue;
} else {
Content = "";
}
return Content;
}
if (MSIE4) {
Content = Element.innerText;
return Content;
}
return false;
}
function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
var Attribute;
var Element = getElement(Mode, Identifier, ElementNumber);
if (!Element) {
return false;
}
if (DOM || MSIE4) {
Attribute = Element.getAttribute(AttributeName);
return Attribute;
}
if (NS4) {
if (typeof Element[ElementNumber] == "object") {
Attribute = Element[ElementNumber][AttributeName];
} else {
Attribute = Element[AttributeName]
}
return Attribute;
}
return false;
}
function setContent (Mode, Identifier, ElementNumber, Text) {
var Element = getElement(Mode, Identifier, ElementNumber);
if (!Element) {
return false;
}
if (DOM && Element.firstChild) {
Element.firstChild.nodeValue = Text;
return true;
}
if (MSIE4) {
Element.innerText = Text;
return true;
}
if (NS4) {
Element.document.open();
Element.document.write(Text);
Element.document.close();
return true;
}
}
zurück zur Beschreibung der Bibliothek