由于Ajax的火爆,所以我会重点介绍与它相关的一些技术。下面的文档已经写了很久了,由于上一篇的尖括号搞的我非常之烦,现在才贴出来,见谅。
我将从Window,XMLHttpRequest等这几个主要接口出发(Document前面已经描述了),描述客户端Javascript编程的主要轮廓。另外,值得注意的是,这个领域的变化仍然非常剧烈,我不保证我描述的东西都可用。无论是现在(我描述的东西还太新)还是以后(而且还没有定型)。
interface XMLHttpRequest {
attribute EventListener onreadystatechange;
readonly attribute unsigned short readyState;
void open(in DOMString method, in DOMString uri);
void open(in DOMString method, in DOMString uri, in boolean async);
void open(in DOMString method, in DOMString uri, in boolean async, in DOMString user);
void open(in DOMString method, in DOMString uri, in boolean async, in DOMString user, in DOMString password);
void setRequestHeader(in DOMString header, in DOMString value) raises(DOMException);
void send(in DOMString data) raises(DOMException);
void send(in Document data) raises(DOMException);
void abort();
DOMString getAllResponseHeaders();
DOMString getResponseHeader(in DOMString header);
attribute DOMString responseText;
attribute Document responseXML;
attribute unsigned short status;
// raises(DOMException) on retrieval
attribute DOMString statusText;
// raises(DOMException) on retrieval
};
interface Item {
readonly attribute boolean exists;
readonly attribute DOMString name;
};
interface IntegerItem : Item {
readonly attribute long value;
};
interface BooleanItem : Item {
attribute boolean value;
};
interface StringItem : Item {
readonly attribute DOMString value;
};
interface ContentItem : Item {
attribute Node nodeArg;
attribute unsigned long offset;
};
interface Match {
// MatchTestGroup
const unsigned short IS_EQUAL = 0;
const unsigned short IS_NOT_EQUAL = 1;
const unsigned short INT_PRECEDES = 2;
const unsigned short INT_PRECEDES_OR_EQUALS = 3;
const unsigned short INT_FOLLOWS = 4;
const unsigned short INT_FOLLOWS_OR_EQUALS = 5;
const unsigned short STR_STARTS_WITH = 6;
const unsigned short STR_ENDS_WITH = 7;
const unsigned short STR_CONTAINS = 8;
const unsigned short SET_ANY = 9;
const unsigned short SET_ALL = 10;
const unsigned short SET_NOT_ANY = 11;
const unsigned short SET_NOT_ALL = 12;
readonly attribute unsigned short test;
};
interface MatchInteger : Match {
readonly attribute DOMString name;
readonly attribute long value;
};
interface MatchBoolean : Match {
readonly attribute DOMString name;
readonly attribute boolean value;
};
interface MatchString : Match {
readonly attribute DOMString name;
readonly attribute DOMString value;
};
interface MatchContent : Match {
readonly attribute DOMString name;
readonly attribute Node nodeArg;
readonly attribute unsigned long offset;
};
interface MatchSet : Match {
readonly attribute Node nodeArg;
void addMatch(in Match add);
Match getMatch(in unsigned long index);
};
interface Segment : Match {
attribute Match criteria;
attribute DOMString order;
void addItem(in Item add);
MatchString createMatchString(in unsigned short test, in DOMString name, in DOMString value);
MatchInteger createMatchInteger(in unsigned short test, in DOMString name, in long value);
MatchBoolean createMatchBoolean(in unsigned short test, in DOMString name, in boolean value);
MatchContent createMatchContent(in unsigned short test, in DOMString name, in unsigned long offset, in Node nodeArg);
MatchSet createMatchSet(in unsigned short test);
StringItem createStringItem(in DOMString name);
IntegerItem createIntegerItem(in DOMString name);
BooleanItem createBooleanItem(in DOMString name);
ContentItem createContentItem(in DOMString name);
void getItem(in unsigned long index);
boolean getNext();
};
interface View {
void select(in Node boundary, in unsigned long offset, in boolean extend, in boolean add);
Segment createSegment();
boolean matchFirstSegment(inout Segment todo) raises(DOMException);
long getIntegerProperty(in DOMString name) raises(DOMException);
DOMString getStringProperty(in DOMString name) raises(DOMException);
boolean getBooleanProperty(in boolean name) raises(DOMException);
Node getContentPropertyNode(in DOMString name) raises(DOMException);
unsigned long getContentPropertyOffset(in DOMString name) raises(DOMException);
};
interface VisualView {
readonly attribute DOMString fontScheme;
readonly attribute unsigned long width;
readonly attribute unsigned long height;
readonly attribute unsigned long horizontalDPI;
readonly attribute unsigned long verticalDPI;
VisualCharacter createVisualCharacter();
VisualCharacterRun createVisualCharacterRun();
VisualFrame createVisualFrame();
VisualImage createVisualImage();
VisualFormButton createVisualFormButton();
VisualFormField createVisualFormField();
void select(in Node boundary, n unsigned long offset, in boolean extend, in boolean add);
void matchSegment(in VisualResource segment);
};
interface VisualResource {
};
interface VisualFont : VisualResource {
attribute DOMString matchFontName;
readonly attribute boolean exists;
readonly attribute DOMString fontName;
boolean getNext();
};
interface VisualSegment : VisualResource {
attribute boolean matchPosition;
attribute boolean matchInside;
attribute boolean matchContaining;
attribute long matchX;
attribute long matchY;
attribute long matchXR;
attribute long matchYR;
attribute boolean matchContent;
attribute boolean matchRange;
attribute Node matchNode;
attribute unsigned long matchOffset;
attribute Node matchNodeR;
attribute unsigned long matchOffsetR;
attribute boolean matchContainsSelected;
attribute boolean matchContainsVisible;
readonly attribute boolean exists;
readonly attribute Node startNode;
readonly attribute unsigned long startOffset;
readonly attribute Node endNode;
readonly attribute unsigned long endOffset;
readonly attribute long topOffset;
readonly attribute long bottomOffset;
readonly attribute long leftOffset;
readonly attribute long rightOffset;
readonly attribute unsigned long width;
readonly attribute unsigned long height;
readonly attribute boolean selected;
readonly attribute boolean visible;
readonly attribute unsigned long foregroundColor;
readonly attribute unsigned long backgroundColor;
readonly attribute DOMString fontName;
readonly attribute DOMString fontHeight;
boolean getNext();
};
interface VisualCharacter : VisualSegment {
};
interface VisualCharacterRun : VisualSegment {
};
interface VisualFrame : VisualSegment {
readonly attribute VisualSegment embedded;
};
interface VisualImage : VisualSegment {
readonly attribute DOMString imageURL;
readonly attribute boolean isLoaded;
};
interface VisualFormButton : VisualSegment {
readonly attribute boolean isPressed;
};
interface VisualFormField : VisualSegment {
readonly attribute DOMString formValue;
};
interface EmbeddingElement {
readonly attribute dom::Document contentDocument;
readonly attribute Window contentWindow;
};
// behavior is always special in ECMAScript, this is defined only for the benefit
// of other languages
interface TimerListener {
// what to put here?
};
interface AbstractView {
readonly attribute DocumentView document;
};
interface DocumentView {
readonly attribute AbstractView defaultView;
};
interface Window : views::AbstractView {
// self-references
readonly attribute Window window;
readonly attribute Window self;
// assigning this has special behavior in ECMAScript, but it is otherwise
// read only. specifically, in ES a string URI can be assigned to location,
// having the same effect as location.assign(URI)
readonly attribute Location location;
// name attribute of referencing frame/iframe/object, or name passed to
// window.open
attribute dom::DOMString name;
// global object of containing document
readonly attribute Window parent;
// global object of outermost containing document
readonly attribute Window top;
// referencing <html:frame>, <html:iframe>, <html:object>, <svg:foreignObject>,
// <svg:animation> or other embedding point, or null if none
readonly attribute dom::Element frameElement;
// one-shot timer
long setTimeout(in TimerListener listener, in long milliseconds);
void clearTimeout(in long timerID);
// repeating timer
long setInterval(in TimerListener listener, in long milliseconds);
void clearInterval(in long timerID);
};
interface DocumentWindow : views::DocumentView {
readonly attribute Location location;
};
interface Location {
attribute dom::DOMString href;
// pieces of the URI, per the generic URI syntax
attribute dom::DOMString hash;
attribute dom::DOMString host;
attribute dom::DOMString hostname;
attribute dom::DOMString pathname;
attribute dom::DOMString port;
attribute dom::DOMString protocol;
attribute dom::DOMString search;
void assign(in dom::DOMString url);
void replace(in dom::DOMString url);
void reload();
dom::DOMString toString();
};
我将从Window,XMLHttpRequest等这几个主要接口出发(Document前面已经描述了),描述客户端Javascript编程的主要轮廓。另外,值得注意的是,这个领域的变化仍然非常剧烈,我不保证我描述的东西都可用。无论是现在(我描述的东西还太新)还是以后(而且还没有定型)。
interface XMLHttpRequest {
attribute EventListener onreadystatechange;
readonly attribute unsigned short readyState;
void open(in DOMString method, in DOMString uri);
void open(in DOMString method, in DOMString uri, in boolean async);
void open(in DOMString method, in DOMString uri, in boolean async, in DOMString user);
void open(in DOMString method, in DOMString uri, in boolean async, in DOMString user, in DOMString password);
void setRequestHeader(in DOMString header, in DOMString value) raises(DOMException);
void send(in DOMString data) raises(DOMException);
void send(in Document data) raises(DOMException);
void abort();
DOMString getAllResponseHeaders();
DOMString getResponseHeader(in DOMString header);
attribute DOMString responseText;
attribute Document responseXML;
attribute unsigned short status;
// raises(DOMException) on retrieval
attribute DOMString statusText;
// raises(DOMException) on retrieval
};
interface Item {
readonly attribute boolean exists;
readonly attribute DOMString name;
};
interface IntegerItem : Item {
readonly attribute long value;
};
interface BooleanItem : Item {
attribute boolean value;
};
interface StringItem : Item {
readonly attribute DOMString value;
};
interface ContentItem : Item {
attribute Node nodeArg;
attribute unsigned long offset;
};
interface Match {
// MatchTestGroup
const unsigned short IS_EQUAL = 0;
const unsigned short IS_NOT_EQUAL = 1;
const unsigned short INT_PRECEDES = 2;
const unsigned short INT_PRECEDES_OR_EQUALS = 3;
const unsigned short INT_FOLLOWS = 4;
const unsigned short INT_FOLLOWS_OR_EQUALS = 5;
const unsigned short STR_STARTS_WITH = 6;
const unsigned short STR_ENDS_WITH = 7;
const unsigned short STR_CONTAINS = 8;
const unsigned short SET_ANY = 9;
const unsigned short SET_ALL = 10;
const unsigned short SET_NOT_ANY = 11;
const unsigned short SET_NOT_ALL = 12;
readonly attribute unsigned short test;
};
interface MatchInteger : Match {
readonly attribute DOMString name;
readonly attribute long value;
};
interface MatchBoolean : Match {
readonly attribute DOMString name;
readonly attribute boolean value;
};
interface MatchString : Match {
readonly attribute DOMString name;
readonly attribute DOMString value;
};
interface MatchContent : Match {
readonly attribute DOMString name;
readonly attribute Node nodeArg;
readonly attribute unsigned long offset;
};
interface MatchSet : Match {
readonly attribute Node nodeArg;
void addMatch(in Match add);
Match getMatch(in unsigned long index);
};
interface Segment : Match {
attribute Match criteria;
attribute DOMString order;
void addItem(in Item add);
MatchString createMatchString(in unsigned short test, in DOMString name, in DOMString value);
MatchInteger createMatchInteger(in unsigned short test, in DOMString name, in long value);
MatchBoolean createMatchBoolean(in unsigned short test, in DOMString name, in boolean value);
MatchContent createMatchContent(in unsigned short test, in DOMString name, in unsigned long offset, in Node nodeArg);
MatchSet createMatchSet(in unsigned short test);
StringItem createStringItem(in DOMString name);
IntegerItem createIntegerItem(in DOMString name);
BooleanItem createBooleanItem(in DOMString name);
ContentItem createContentItem(in DOMString name);
void getItem(in unsigned long index);
boolean getNext();
};
interface View {
void select(in Node boundary, in unsigned long offset, in boolean extend, in boolean add);
Segment createSegment();
boolean matchFirstSegment(inout Segment todo) raises(DOMException);
long getIntegerProperty(in DOMString name) raises(DOMException);
DOMString getStringProperty(in DOMString name) raises(DOMException);
boolean getBooleanProperty(in boolean name) raises(DOMException);
Node getContentPropertyNode(in DOMString name) raises(DOMException);
unsigned long getContentPropertyOffset(in DOMString name) raises(DOMException);
};
interface VisualView {
readonly attribute DOMString fontScheme;
readonly attribute unsigned long width;
readonly attribute unsigned long height;
readonly attribute unsigned long horizontalDPI;
readonly attribute unsigned long verticalDPI;
VisualCharacter createVisualCharacter();
VisualCharacterRun createVisualCharacterRun();
VisualFrame createVisualFrame();
VisualImage createVisualImage();
VisualFormButton createVisualFormButton();
VisualFormField createVisualFormField();
void select(in Node boundary, n unsigned long offset, in boolean extend, in boolean add);
void matchSegment(in VisualResource segment);
};
interface VisualResource {
};
interface VisualFont : VisualResource {
attribute DOMString matchFontName;
readonly attribute boolean exists;
readonly attribute DOMString fontName;
boolean getNext();
};
interface VisualSegment : VisualResource {
attribute boolean matchPosition;
attribute boolean matchInside;
attribute boolean matchContaining;
attribute long matchX;
attribute long matchY;
attribute long matchXR;
attribute long matchYR;
attribute boolean matchContent;
attribute boolean matchRange;
attribute Node matchNode;
attribute unsigned long matchOffset;
attribute Node matchNodeR;
attribute unsigned long matchOffsetR;
attribute boolean matchContainsSelected;
attribute boolean matchContainsVisible;
readonly attribute boolean exists;
readonly attribute Node startNode;
readonly attribute unsigned long startOffset;
readonly attribute Node endNode;
readonly attribute unsigned long endOffset;
readonly attribute long topOffset;
readonly attribute long bottomOffset;
readonly attribute long leftOffset;
readonly attribute long rightOffset;
readonly attribute unsigned long width;
readonly attribute unsigned long height;
readonly attribute boolean selected;
readonly attribute boolean visible;
readonly attribute unsigned long foregroundColor;
readonly attribute unsigned long backgroundColor;
readonly attribute DOMString fontName;
readonly attribute DOMString fontHeight;
boolean getNext();
};
interface VisualCharacter : VisualSegment {
};
interface VisualCharacterRun : VisualSegment {
};
interface VisualFrame : VisualSegment {
readonly attribute VisualSegment embedded;
};
interface VisualImage : VisualSegment {
readonly attribute DOMString imageURL;
readonly attribute boolean isLoaded;
};
interface VisualFormButton : VisualSegment {
readonly attribute boolean isPressed;
};
interface VisualFormField : VisualSegment {
readonly attribute DOMString formValue;
};
interface EmbeddingElement {
readonly attribute dom::Document contentDocument;
readonly attribute Window contentWindow;
};
// behavior is always special in ECMAScript, this is defined only for the benefit
// of other languages
interface TimerListener {
// what to put here?
};
interface AbstractView {
readonly attribute DocumentView document;
};
interface DocumentView {
readonly attribute AbstractView defaultView;
};
interface Window : views::AbstractView {
// self-references
readonly attribute Window window;
readonly attribute Window self;
// assigning this has special behavior in ECMAScript, but it is otherwise
// read only. specifically, in ES a string URI can be assigned to location,
// having the same effect as location.assign(URI)
readonly attribute Location location;
// name attribute of referencing frame/iframe/object, or name passed to
// window.open
attribute dom::DOMString name;
// global object of containing document
readonly attribute Window parent;
// global object of outermost containing document
readonly attribute Window top;
// referencing <html:frame>, <html:iframe>, <html:object>, <svg:foreignObject>,
// <svg:animation> or other embedding point, or null if none
readonly attribute dom::Element frameElement;
// one-shot timer
long setTimeout(in TimerListener listener, in long milliseconds);
void clearTimeout(in long timerID);
// repeating timer
long setInterval(in TimerListener listener, in long milliseconds);
void clearInterval(in long timerID);
};
interface DocumentWindow : views::DocumentView {
readonly attribute Location location;
};
interface Location {
attribute dom::DOMString href;
// pieces of the URI, per the generic URI syntax
attribute dom::DOMString hash;
attribute dom::DOMString host;
attribute dom::DOMString hostname;
attribute dom::DOMString pathname;
attribute dom::DOMString port;
attribute dom::DOMString protocol;
attribute dom::DOMString search;
void assign(in dom::DOMString url);
void replace(in dom::DOMString url);
void reload();
dom::DOMString toString();
};