mobileFX WebKitX ActiveX
Advanced Topics / Accessing HTML5 DOM
In This Topic
    Accessing HTML5 DOM
    In This Topic

    WebKitX control provides access to HTML5 DOM through CSS3 selector-based API methods as well as COM DOM Wrappers.

    In CSS and CSS3, selectors are patterns used to select the elements you want to style. In WebKitX is used for accessing a single DOM node while methods provide read and write access to node attributes, style and markup.

    List of CSS3 selector-based DOM access methods

    GetAttribute - Returns an attribute value of an HTML5 Element.

    GetAttributes - Returns a space-separated string list of attribute=value pairs of all element attributes by selector.

    RemoveAttribute - Removes an attribute from an HTML5 Element.

    SetAttribute - Sets an attribute value of an HTML5 Element.

    SetAttributes - Sets a space-separated string list of attribute=value pairs to an HTML5 Element.

    GetStyle - Returns a setting value from style.cssText of an HTML5 Element.

    GetCssText - Return the declared style or the computed style of an HTML5 Element.

    SetCssText - Sets the style.cssText property of an HTML5 Element.

    GetInnerHTML - Return the inner HTML of an HTML5 Element.

    SetInnerHTML - Set the inner HTML of an HTML5 Element.

    GetOuterHTML - Return the outer HTML of an HTML5 Element.

    SetOuterHTML - Set the outer HTML of an HTML5 Element.

     

    Accessing and Manipulating HTML5 DOM Programmatically with COM Wrappers

    In an attempt to provide similar functionality with Microsoft Web Browser Control, WebKitX offers limited access and DOM manipulation using COM Wrappers. A COM Wrapper wraps native WebKit Blink HTML5 Elements and exposes them to the OLE/COM environment. WebKitX HTML5 COM Wrappers are volatile Just-In-Time (JIT) COM objects, meaning that WebKitX does not reference-count the provided COM object. Internally each COM Wrapper has a CSS3 Selector to the underlying native object and the wrapper is valid for as long as the CSS3 Selector remains valid.

    Accessing and Manipulating HTML5 DOM Programmatically with COM Wrappers

    Accessing and Manipulating HTML5 DOM Programmatically with COM Wrappers

    WebKitX offers properties and methods that provide DOM Wrappers:

    Document - Returns a COM Wrapper of HTML5 Document object.

    Window - Returns a COM Wrapper of HTML5 Window object.

    QuerySelector - Given a valid CSS3 Selector, returns a COM Wrapper for an HTML5 Element object.

    Using DOM Wrappers
    Copy Code
    Private Sub mnuDomAccss_Click()
    
        Dim Element As HTML5Element
        Set Element = WebKitX1.QuerySelector(CurrentSelector)
        Debug.Print Element.ClassName
        
        WebKitX1.Document.Body.Style.Border = "1px solid red"
        Debug.Print WebKitX1.Document.Body.FirstElementChild.NextElementSibling.InnerHTML
    
        ' Break in VB6 debugger.
        ' Add a watch for Element and expand it.
        Debug.Assert False
    
    End Sub
    See Also