Module Js_of_ocaml.Dom_html
DOM HTML binding
This is a partial binding to the DOM HTML API.
CSS style declaration
class type cssStyleDeclaration = object ... endEvents
type (-'a, -'b) event_listener= ('a, 'b) Dom.event_listenerThe type of event listener functions. The first type parameter
'ais the type of the target object; the second parameter'bis the type of the event object.
class type event = object ... endand 'a customEvent = object ... endand focusEvent = object ... endand mouseEvent = object ... endand keyboardEvent = object ... endand mousewheelEvent = object ... endand mouseScrollEvent = object ... endand touchEvent = object ... endand touchList = object ... endand touch = object ... endand dragEvent = object ... endand dataTransfer = object ... endand eventTarget = object ... endCommon properties of event target objects:
onclick,onkeypress, ...
and popStateEvent = object ... endand pointerEvent = object ... endand storageEvent = object ... endand storage = object ... endStorage
and hashChangeEvent = object ... endand animationEvent = object ... endand mediaEvent = object ... endHTML elements
and nodeSelector = object ... endand tokenList = object ... endand element = object ... endProperties common to all HTML elements
and clientRect = object ... endRectangular box (used for element bounding boxes)
and clientRectList = object ... endclass type 'node collection = object ... endCollection of HTML elements
class type htmlElement = elementclass type headElement = object ... endclass type linkElement = object ... endclass type titleElement = object ... endclass type metaElement = object ... endclass type baseElement = object ... endclass type styleElement = object ... endclass type bodyElement = elementclass type formElement = object ... endclass type optGroupElement = object ... endclass type optionElement = object ... endclass type selectElement = object ... endclass type inputElement = object ... endclass type textAreaElement = object ... endclass type buttonElement = object ... endclass type labelElement = object ... endclass type fieldSetElement = object ... endclass type legendElement = object ... endclass type uListElement = elementclass type oListElement = elementclass type dListElement = elementclass type divElement = elementclass type paragraphElement = elementclass type headingElement = elementclass type quoteElement = object ... endclass type preElement = elementclass type modElement = object ... endclass type anchorElement = object ... endclass type imageElement = object ... endclass type objectElement = object ... endclass type paramElement = object ... endclass type areaElement = object ... endclass type mapElement = object ... endclass type scriptElement = object ... endclass type embedElement = object ... endclass type tableCellElement = object ... endclass type tableRowElement = object ... endclass type tableColElement = object ... endclass type tableSectionElement = object ... endclass type tableCaptionElement = elementclass type tableElement = object ... endclass type timeRanges = object ... endtype networkState=|NETWORK_EMPTY|NETWORK_IDLE|NETWORK_LOADING|NETWORK_NO_SOURCEtype readyState=|HAVE_NOTHING|HAVE_METADATA|HAVE_CURRENT_DATA|HAVE_FUTURE_DATA|HAVE_ENOUGH_DATA
class type mediaElement = object ... endclass type audioElement = object ... endclass type videoElement = object ... endCanvas object
val _2d_ : context
class type canvasElement = object ... endand canvasRenderingContext2D = object ... endand canvasGradient = object ... endand textMetrics = object ... endand imageData = object ... endand canvasPixelArray = object ... endval pixel_get : canvasPixelArray Js.t -> int -> intval pixel_set : canvasPixelArray Js.t -> int -> int -> unit
class type range = object ... endObject representing a range *
class type selection = object ... endInformation on current selection
Document objects
class type document = object ... endval getElementById_opt : string -> element Js.t optiongetElementById_opt idreturns the element with the ididin the current document. It returnsNoneif there are no such element
val getElementById_exn : string -> element Js.tgetElementById_exn idreturns the element with the ididin the current document. It raises if there are no such element
val getElementById_coerce : string -> (element Js.t -> 'a Js.opt) -> 'a optiongetElementById_coerce id coercereturns the element with the ididin the current document and attempt to coerce it using the providedcoercefunction. It returnsNoneif there are no such element or if thecoercefunction returnsJs.none. Typical usage is the following:match Dom_html.getElementById_coerce "myinput" Dom_html.CoerceTo.input with | None -> .. | Some input -> ..
Window objects
class type location = object ... endLocation information
val location_origin : location Js.t -> Js.js_string Js.t
class type history = object ... endBrowser history information
class type undoManager = object ... endUndo manager
Navigator information
class type screen = object ... endclass type applicationCache = object ... endclass type _URL = object ... endclass type window = object ... endSpecification of window objects
class type frameSetElement = object ... endclass type frameElement = object ... endclass type iFrameElement = object ... endEvent handlers
val no_handler : ('a, 'b) event_listenersee
Dom.no_handler
val handler : (event Js.t as 'b -> bool Js.t) -> ('a, 'b) event_listenersee
Dom.handler
val full_handler : ('a -> event Js.t as 'b -> bool Js.t) -> ('a, 'b) event_listenersee
Dom.full_handler
val invoke_handler : ('a, 'b) event_listener -> 'a -> 'b -> bool Js.tsee
Dom.invoke_handler
val eventRelatedTarget : mouseEvent Js.t -> element Js.t Js.optReturns this event related target.
module Event : sig ... endEvent types:
mousedown,keypress, ...
type event_listener_id= Dom.event_listener_id
val addEventListenerWithOptions : eventTarget Js.t as 'a -> 'b Event.typ -> ?capture:bool Js.t -> ?once:bool Js.t -> ?passive:bool Js.t -> ('a, 'b) event_listener -> event_listener_idAdd an event listener. This function matches the option-object variant of the
addEventListenerDOM method, except that it returns an id for removing the listener.
val addEventListener : eventTarget Js.t as 'a -> 'b Event.typ -> ('a, 'b) event_listener -> bool Js.t -> event_listener_idAdd an event listener. This function matches the useCapture boolean variant of the
addEventListenerDOM method, except that it returns an id for removing the listener.
val removeEventListener : event_listener_id -> unitRemove the given event listener.
val addMousewheelEventListenerWithOptions : eventTarget Js.t as 'a -> ?capture:bool Js.t -> ?once:bool Js.t -> ?passive:bool Js.t -> (mouseEvent Js.t -> dx:int -> dy:int -> bool Js.t) -> event_listener_idAdd a mousewheel event listener with option-object variant of the
addEventListenerDOM method. The callback is provided the event and the numbers of ticks the mouse wheel moved. Positive means down / right.
val addMousewheelEventListener : eventTarget Js.t as 'a -> (mouseEvent Js.t -> dx:int -> dy:int -> bool Js.t) -> bool Js.t -> event_listener_idAdd a mousewheel event listener with the useCapture boolean variant of the
addEventListenerDOM method. The callback is provided the event and the numbers of ticks the mouse wheel moved. Positive means down / right.
val createCustomEvent : ?bubbles:bool -> ?cancelable:bool -> ?detail:'a -> 'a customEvent Js.t Event.typ -> 'a customEvent Js.tSee
Dom.createCustomEvent
Mouse event helper functions
val buttonPressed : mouseEvent Js.t -> mouse_button
Position helper functions
val eventAbsolutePosition : mouseEvent Js.t -> int * intReturns the absolute position of the mouse pointer.
Key event helper functions
module Keyboard_code : sig ... endUse
Keyboard_codewhen you want to identify a key that the user pressed. This should be invoked for keydown and keyup events, not keypress events.
module Keyboard_key : sig ... endUse
Keyboard_keywhen you want to identify the character that the user typed. This should only be invoked on keypress events, not keydown or keyup events.
Helper functions for creating HTML elements
val createHtml : document Js.t -> htmlElement Js.tval createHead : document Js.t -> headElement Js.tval createLink : document Js.t -> linkElement Js.tval createTitle : document Js.t -> titleElement Js.tval createMeta : document Js.t -> metaElement Js.tval createBase : document Js.t -> baseElement Js.tval createStyle : document Js.t -> styleElement Js.tval createBody : document Js.t -> bodyElement Js.tval createForm : document Js.t -> formElement Js.tval createOptgroup : document Js.t -> optGroupElement Js.tval createOption : document Js.t -> optionElement Js.tval createSelect : ?_type:Js.js_string Js.t -> ?name:Js.js_string Js.t -> document Js.t -> selectElement Js.tval createInput : ?_type:Js.js_string Js.t -> ?name:Js.js_string Js.t -> document Js.t -> inputElement Js.tval createTextarea : ?_type:Js.js_string Js.t -> ?name:Js.js_string Js.t -> document Js.t -> textAreaElement Js.tval createButton : ?_type:Js.js_string Js.t -> ?name:Js.js_string Js.t -> document Js.t -> buttonElement Js.tval createLabel : document Js.t -> labelElement Js.tval createFieldset : document Js.t -> fieldSetElement Js.tval createLegend : document Js.t -> legendElement Js.tval createUl : document Js.t -> uListElement Js.tval createOl : document Js.t -> oListElement Js.tval createDl : document Js.t -> dListElement Js.tval createLi : document Js.t -> liElement Js.tval createDiv : document Js.t -> divElement Js.tval createEmbed : document Js.t -> embedElement Js.tval createP : document Js.t -> paragraphElement Js.tval createH1 : document Js.t -> headingElement Js.tval createH2 : document Js.t -> headingElement Js.tval createH3 : document Js.t -> headingElement Js.tval createH4 : document Js.t -> headingElement Js.tval createH5 : document Js.t -> headingElement Js.tval createH6 : document Js.t -> headingElement Js.tval createQ : document Js.t -> quoteElement Js.tval createBlockquote : document Js.t -> quoteElement Js.tval createPre : document Js.t -> preElement Js.tval createBr : document Js.t -> brElement Js.tval createHr : document Js.t -> hrElement Js.tval createIns : document Js.t -> modElement Js.tval createDel : document Js.t -> modElement Js.tval createA : document Js.t -> anchorElement Js.tval createImg : document Js.t -> imageElement Js.tval createObject : document Js.t -> objectElement Js.tval createParam : document Js.t -> paramElement Js.tval createMap : document Js.t -> mapElement Js.tval createArea : document Js.t -> areaElement Js.tval createScript : document Js.t -> scriptElement Js.tval createTable : document Js.t -> tableElement Js.tval createCaption : document Js.t -> tableCaptionElement Js.tval createCol : document Js.t -> tableColElement Js.tval createColgroup : document Js.t -> tableColElement Js.tval createThead : document Js.t -> tableSectionElement Js.tval createTfoot : document Js.t -> tableSectionElement Js.tval createTbody : document Js.t -> tableSectionElement Js.tval createTr : document Js.t -> tableRowElement Js.tval createTh : document Js.t -> tableCellElement Js.tval createTd : document Js.t -> tableCellElement Js.tval createSub : document Js.t -> element Js.tval createSup : document Js.t -> element Js.tval createSpan : document Js.t -> element Js.tval createTt : document Js.t -> element Js.tval createI : document Js.t -> element Js.tval createB : document Js.t -> element Js.tval createBig : document Js.t -> element Js.tval createSmall : document Js.t -> element Js.tval createEm : document Js.t -> element Js.tval createStrong : document Js.t -> element Js.tval createCite : document Js.t -> element Js.tval createDfn : document Js.t -> element Js.tval createCode : document Js.t -> element Js.tval createSamp : document Js.t -> element Js.tval createKbd : document Js.t -> element Js.tval createVar : document Js.t -> element Js.tval createAbbr : document Js.t -> element Js.tval createDd : document Js.t -> element Js.tval createDt : document Js.t -> element Js.tval createNoscript : document Js.t -> element Js.tval createAddress : document Js.t -> element Js.tval createFrameset : document Js.t -> frameSetElement Js.tval createFrame : document Js.t -> frameElement Js.tval createIframe : document Js.t -> iFrameElement Js.tval createAudio : document Js.t -> audioElement Js.tval createVideo : document Js.t -> videoElement Js.t
val createCanvas : document Js.t -> canvasElement Js.t- raises Canvas_not_available
when canvas elements are not supported by the browser.
Coercion functions
val element : Js_of_ocaml__.Dom.#element Js.t -> element Js.tCoercion from a general DOM element to an HTML element. (Unsafe in general.)
type taggedElement=
val tagged : element Js.t -> taggedElementval opt_tagged : element Js.t Js.opt -> taggedElement option
type taggedEvent=|MouseEvent of mouseEvent Js.t|KeyboardEvent of keyboardEvent Js.t|MousewheelEvent of mousewheelEvent Js.t|MouseScrollEvent of mouseScrollEvent Js.t|PopStateEvent of popStateEvent Js.t|OtherEvent of event Js.t
val taggedEvent : event Js.t -> taggedEventval opt_taggedEvent : event Js.t Js.opt -> taggedEvent optionval stopPropagation : event Js.t -> unit
module CoerceTo : sig ... endval setTimeout : (unit -> unit) -> float -> timeout_id_safeSame as
Dom_html.window##setTimeout cb msbut prevents overflow with delay greater than 24 days.
val clearTimeout : timeout_id_safe -> unitval js_array_of_collection : element collection Js.t -> element Js.t Js.js_array Js.tConvert a
Dom_html.collectionto a Js array
Deprecated function.
val _requestAnimationFrame : (unit -> unit) Js.callback -> unitCall the appropriate
requestAnimationFramemethod variant (depending on the navigator), or sleep for a short amount of time when there no such method is provided. We currently prefix the function name with as underscore as the interface of this function is not completely standardized yet. Thus, we leave the room to a function with a possibly refined type.This function is deprecated. Use the requestAnimationFrame of the window object instead.