mobileFX WebKitX CEF3 ActiveX 4.x
WebKitXCEF3Lib ActiveX Control / WebKitXCEF3 Object / QuerySelector Method

Selector can be either the CSS3 Selector of the HTML5 Element you wish to manipulate, or "document" for the DOM Document, or "window" for DOM Window objects respectively. If you are unfamiliar with CSS3 Selectors have a look in Finding the correct CSS3 Selector article.

In This Topic
    QuerySelector Method
    In This Topic
    Description

    Creates and returns a volatile Just-In-Time (JIT) COM Wrapper / Proxy for an HTML5 Element, or Document, or Window objects.

    This feature is designed to allow basic read / write DOM manipulation without resolving to JavaScript execution.

    Syntax
    Visual Basic
    Public Function QuerySelector( _
       ByVal Selector As String _
    ) As HTML5NodeElement
    Parameters
    Selector

    Selector can be either the CSS3 Selector of the HTML5 Element you wish to manipulate, or "document" for the DOM Document, or "window" for DOM Window objects respectively. If you are unfamiliar with CSS3 Selectors have a look in Finding the correct CSS3 Selector article.

    Return Type

    An HTML5Element COM wrapper / proxy that can be used for read/write access to HTML5 DOM.

    Remarks

    HTML5Element COM Class is light-weight wrapper / proxy for HTML5 Elements, Document and Window objects that bridges the gap between COM and Chromium worlds.

    An instance of this COM class holds internally a CSS3-like selector that is used as and when needed for accessing the underlying HTML5 DOM Node of the WebKit Blink Rendering Engine. This COM object is taking advantage of WebKitX IPC mechanism in order to read / write DOM attributes or CSS3 styles synchronously. You may keep a reference to an HTML5Element instance for as long as the WebKitX control and its HTML5 Page are loaded and dispose references when you change page or destroy the control.

    Accessing and Manipulating HTML5 DOM Programmatically with COM Wrappers

    Accessing and Manipulating HTML5 DOM Programmatically with COM Wrappers

    The term "Just-In-Time" means that WebKitX does not keep reference of HTML5Element objects; instances are created and returned to your code as needed. Please note that every time you access a property or method of an HTML5Element instance, WebKitX performs an IPC transaction to the Blink Rendering Engine which resides in out-of-process CEF3 executables. For that reason you are advised to use this feature orthologically and avoid unnecessary interactions as it may slow down rendering performance.

    Example
    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
    Private Sub mnuDomCompare_Click()
    
        Dim Element1 As HTML5Element
        Dim Element2 As HTML5Element
        
        Set Element1 = WebKitX1.QuerySelector("body")
        Set Element2 = WebKitX1.QuerySelector("body")
        
        ' This will always be False
        Debug.Print Element1 Is Element2
        
        ' This is the right way
        Debug.Print Element1.Selector = Element2.Selector
        
    End Sub
    See Also