Hi, David.

Unfortunately, this only works with Internet Explorer. Firefox does not expose its object model through COM. If you need access to Firefox, you'll probably want to write a Firefox add-in that exposes content.

Save the sample script below as ie_test.vbs, and load it as a program specific app with IE, and then go to any page at gwmicro.com, and you'll hear, "The url of this link is blah" when you tab through links, and "the type of this input is blah" when you tab through form controls (or at least input elements like edit boxes).

This sample works with both IE8 under XP and IE11under Windows 8.1 (and presumably all flavors in between, although I didn't test them).

Thanks,

Aaron

' Begin ie_test.vbs
Option Explicit

Dim NOM : Set NOM = Nothing
Dim DOMEvents : DOMEvents = 0
Dim DOMDocumentEvents : DOMDocumentEvents = 0
Dim DOMElementEvents : Set DOMElementEvents = CreateObject("Scripting.Dictionary")

ConnectEvent DesktopWindow, "OnChildActivate", "OnChildActivate"

Sub OnChildActivate(wObj)
    Dim ieChildren, ieChild

    ' Begin
    If wObj.ModuleName = "IEFRAME" And wObj.ClassName = "IEFrame" Then
' The native object model is available in MSHTML's Internet Explorer_Server class, which
        ' there should only ever be visible one of in an IE window.
Set ieChildren = wObj.Children.FilterByClassAndModule("Internet Explorer_Server", "MSHTML")
        For Each ieChild in ieChildren
            If ieChild.Visible Then
                Set NOM = ieChildren(1).NativeObjectModel
                If Not NOM Is Nothing Then
' Connect to the DOM events in case the document reloads, then call the
                    ' onload function to proceed.
                    DOMEvents = ConnectObject(NOM, "DOM_")
                    DOM_onload
                End If
                Exit For
            End If
        Next
    End If
End Sub

Sub DOM_onload()
    Dim document

    ' Begin
    If Not NOM Is Nothing Then
        Set document = NOM.document
        If Not document Is Nothing Then
            ' Disconnect from any existing document events
            If DOMDocumentEvents <> 0 Then
                Disconnect DOMDocumentEvents
                DOMDocumentEvents = 0
            End If
' If the URL of the page we're on contains the gwmicro.com domain, then connect ' to the document events, and call the onreadystatechange function to proceed. If InStr(LCase(document.location.href), LCase("gwmicro.com")) Then DOMDocumentEvents = ConnectObjectWithParameter(document, "DOC_", document)
                DOC_onreadystatechange document
            End If
        End If
    End If
End Sub

Sub DOC_onreadystatechange(document)
    Dim readyState, i, keys, controls, control

    ' Begin
    On Error Resume Next
        readyState = document.readyState
        If Err.Number <> 0 Then
            readyState = Err.Description
        End If
    On Error Goto 0
    If readyState = "complete" Then
        ' Remove any exsting element events
        If DOMElementEvents.Count > 0 Then
            keys = DOMElementEvents.Keys
            For i = 0 To UBound(keys)
                If DOMElementEvents(keys(i)) <> 0 Then
                    Disconnect DOMElementEvents(keys(i))
DOMElementEvents.Remove keys(i)
                End If
            Next
        End If

' Connect to the events of the elements we care about. In this case, we're connecting ' to the events of all input elements, and anchor elements on the page.
        Dim controlTypes : controlTypes = Array("INPUT", "A")
        For i = 0 To UBound(controlTypes)
            Set controls = document.getElementsByTagName(controlTypes(i))
            If controls.length > 0 Then
                DOMElementEvents.RemoveAll
                For Each control In controls
If Not DOMElementEvents.Exists(DOMElementEvents.Count + 1) Then DOMElementEvents.Add DOMElementEvents.Count + 1, ConnectObjectWithParameter(control, "ELEMENT_", control)
                    End If
                Next
            End If
        Next
    End If
End Sub

Sub ELEMENT_onfocus(theControl)
    Select Case TypeName(theControl)
        Case "HTMLAnchorElement"
            Speak "The url of this link is: " & theControl.href
        Case "HTMLInputElement"
            Speak "The type of this input is: " & theControl.type
    End Select
End Sub
' End ie_test.vbs

On 2/3/2014 6:23 PM, David wrote:
Thanks, Aaron,
A snip-it would be great. Will that work in both Internet Explorer, Firefox, and any other software that handles BrowseMode - like mail clients - or, do I have to reconstruct for each application? Asking, since my code gave me one result in IE, and an empty object under Firefox. Sure seems you are right, the BrowseMode offered to us, is lacking. :) Any reason for it not to provide us a direct way to get to the HTML stuff?

Anyway, please provide what you have for sample code, and I will see if I can get anything further with my project here.

thanks,

----- Original Message ----- From: "Aaron Smith" <[email protected]>
To: <[email protected]>
Sent: Monday, February 03, 2014 8:38 PM
Subject: Re: Retrieving a link from the BrowseMode buffer


Hi, David.

Honestly, you're best bet is to get the NativeObjectModel from the IE Window itself, and work with the HTMLWindow2 interface directly (from this you can get the Document object, and workwith the DOM directly). The BrowseMode interface through Window-Eyes scripting is greatly lacking. Ican give you a snippet for getting the IHTMLWindow2 interface if you're interested.

Thanks,

Aaron

On 2/3/2014 7:51 AM, David wrote:
Think I got stuck here, and wonder if someone could give me a bit of first-aid :)
I have the following code:
    Dim BMBuffer: Set BMBuffer = BrowseMode
    Dim BMLineNumber: BMLineNumber = BMBuffer.CursorLine
    Dim BMLine: Set BMLine = BMBuffer.Lines( BMLineNumber)
So far, things work well, and I can get it to speak the line number, and the text of the line. Next, I check on the IsLink boolean, to make sure I am on a link in the buffer. Now, how do I retrieve the actual link - that is, the "http" blah-blah stuff - from my finding? OK, I read in the reference material for WE, and find the DOMNode property. So, I do something like:
 Dim BMNode: Set BMNode = BMLine.DOMNode
If I now test on the TypeName of the BMNode variable, whenever focusing a link, I get the message that it is
 Nothing,
when I am working in Firefox, and in Internet Explorer, I get an object of the type
 DispHtmlTextNode.
Not really sure, why it would return an empty object, when in Firefox, but recognize things well enough in Internet Explorer. Well, computers have their own kind of fun. Anyway, my real trouble here is, how can I make the app tell me the actual "http" stuff for the focused Link, when in BrowseMode? What is the correct syntax here? Any ideas are welcome. Thanks all of you...

--
Aaron Smith
Web Development * App Development * Product Support Specialist
GW Micro, Inc. * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * gwmicro.com

To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.



--
Aaron Smith
Web Development * App Development * Product Support Specialist
GW Micro, Inc. * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * gwmicro.com

To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.

Reply via email to