Welcome Guest Search | Active Topics | Sign In | Register

Javascript injection not working Options
ac2015
Posted: Friday, December 25, 2015 3:50:35 AM
Rank: Member
Groups: Member

Joined: 12/24/2015
Posts: 14
The following code does not do anything for me with EO.WebBrowser.
No exceptions, but just not doing anthing.

In another browser it works fine.

Does anybody see any mistake here?

Quote:
Public Sub SetFocus()

_Browser.WebView.SetFocus()

Try
Dim i&
Dim JS(100) As String

i = i + 1 : JS(i) = "var inputElements = document.getElementsByTagName('input');"
i = i + 1 : JS(i) = "for(i=0; i<inputElements.length; i++)"
i = i + 1 : JS(i) = "{"
i = i + 1 : JS(i) = " if (inputElements[i].type != 'hidden')"
i = i + 1 : JS(i) = " {"
i = i + 1 : JS(i) = " if (inputElements[i].disabled == false)"
i = i + 1 : JS(i) = " {"
i = i + 1 : JS(i) = " inputElements[i].focus();"
i = i + 1 : JS(i) = " inputElements[i].scrollIntoView(true);"
i = i + 1 : JS(i) = " break;"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = "}"

Dim html As String = Join(JS)
_Browser.WebView.EvalScript(String.Format("(function(){{ {0} }})()", html))

Catch ex As Exception
MessageBox.Show(ex.Message.ToString)
End Try

End Sub
ac2015
Posted: Friday, December 25, 2015 4:10:57 AM
Rank: Member
Groups: Member

Joined: 12/24/2015
Posts: 14
Got it.

The following works:

Dim i&
Dim JS(100) As String

i = i + 1 : JS(i) = "var inputElements = document.getElementsByTagName('input');"
i = i + 1 : JS(i) = "for(i=0; i<inputElements.length; i++)"
i = i + 1 : JS(i) = "{"
i = i + 1 : JS(i) = " if (inputElements[i].type != 'hidden')"
i = i + 1 : JS(i) = " {"
i = i + 1 : JS(i) = " if (inputElements[i].disabled == false)"
i = i + 1 : JS(i) = " {"
' If uSetFocusToFirstBox Then
i = i + 1 : JS(i) = " inputElements[i].focus();"
' End If
'If uScrollIntoView Then
i = i + 1 : JS(i) = " inputElements[i].scrollIntoView(true);"
'End If
i = i + 1 : JS(i) = " break;"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = " }"
i = i + 1 : JS(i) = "}"

Dim html As String = Join(JS)

' MessageBox.Show(html)

_webView.EvalScript(html)


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.