Wisej.Web.WebBrowser.eavl(JS) do not works
In this code, please advise:
Public Class CTreeView_basic_01_ForBooks
Inherits TreeView
Dim OWebBrowser As Wisej.Web.WebBrowser
Public Sub New(INOGuid As Guid, ByRef INoWebBrowser As Wisej.Web.WebBrowser)
OWebBrowser = INoWebBrowser
With Me
.Dock = DockStyle.Fill
.ShowPlusMinus = True
.ShowRootLines = True
.ShowNodeToolTips = True
End With
End Sub
Private Sub CTreeView_basic_01_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles Me.NodeMouseClick
Dim OTreeNode As TreeNode = e.Node
Dim searchText As String = OTreeNode.Text
Dim js As String =
“var found = false;
var el = document.body;
if (el.innerText.includes(‘” & searchText.Replace(“”””, “\”””) & “‘)) {
el.style.backgroundColor = ‘yellow’;
found = true;
}
if (!found) alert(‘Nothing Found’);”
OWebBrowser.Eval(js)
End Sub
End Class
Hi,
I’m back with a compilable test case that shows the issue, including the URL I’ve been testing.
The behavior is exactly as I previously described:
01. If you load the tree view with all elements, the JavaScript does not execute at all.
02. If you load it with only 4 elements, the JavaScript executes and displays a message that nothing was found (which is not the issue we’re discussing).
Execute the two buttons in different sessions, not one after another in one session.
Please find source code attached. It is based on NET 4.8
Kind regards!
Hi there,
I tried to reproduce the issue exactly like you stated, and I couldn’t reproduce.
Furthermore, having a TreeView with more than 4 nodes works, there’s no relation as to why having a TreeView with more than 4 nodes would fail evaluating javascript in the WebBrowser component.
At this point, we’re trying to guess what you’re trying to accomplish and it’s beyond the scope of free Wisej.NET support, please verify the javascript you’re trying to execute and make sure everything is escaped correctly.
The only way for us to verify this is to have a compilable, ready-to-run sample that demonstrates the issue reported.
Best Regards,
Alaa
Hi,
I’m coming back with a solution to the problem, whose cause and fix turned out to be utterly absurd.
If a SplitContainer contains a TreeView and a Wisej.Web.WebBrowser, and the TreeView has more than 4 nodes, then Wisej.Web.WebBrowser.Eval(js)
does not execute.
But if the number of nodes is 4 or fewer, the JS does execute.
This bizarre bug makes it impossible to implement an e-book scenario with a browser and a tree view containing more than 4 topics — which is, to put it mildly, EXTREMELY ANNOYING.
Please find images attached.
Hi mgmst,
we need a compilable test case that shows the issue including the URL that you have been testing.
Otherwise we cannot help any further.
Best regards
Frank
When it is in the test application (please find attached), I at least receive “Nothing found” message, which points that JS works.
When it is in a my control for books’ content loading- JS not works at all! Why so? Please advice.
Public Class C_Books_Container
Inherits Panel
Private ОWebBrowser As New CUtils.CInterfaceIni.CInterface.C_Wisej_Web_WebBrowser
Public WithEvents OTV As New CUtils.CInterfaceIni.CInterface.CTreeViewS.CTreeView.CTreeView_basic_01(Guid.NewGuid)
Private OSplitContainer As New SplitContainer
Public Sub New(INOStrURLText As String, INOSTRDelimiter As String, INOSTRDelimiter_Internal As String)
ОWebBrowser.Dock = DockStyle.Fill
OTV.Dock = DockStyle.Fill
With OSplitContainer
.Dock = DockStyle.Fill
.Panel1.Controls.Add(OTV)
.Panel2.Controls.Add(ОWebBrowser)
End With
ОWebBrowser.Url = New Uri(INOStrURLText)
Dim OStringPageContent As String = GetTextFromUrl(INOStrURLText)
F_TableОfContents_Get(OTV, OStringPageContent, INOSTRDelimiter, INOSTRDelimiter_Internal)
Me.Dock = DockStyle.Fill
Me.Controls.Add(OSplitContainer)
End Sub
Private Sub OTV_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles OTV.NodeMouseClick
Dim searchText = “5”
Dim js As String =
”
var found = false;
var elements = document.getElementsByTagName(‘*’);
for (var i = 0; i < elements.length; i++) {
if (elements[i].innerText && elements[i].innerText.includes(‘” & searchText.Replace(“”””, “\”””) & “‘)) {
elements[i].scrollIntoView({behavior: ‘smooth’, block: ‘center’});
elements[i].style.backgroundColor = ‘yellow’;
found = true;
break;
}
}
if (!found) {
alert(‘Nothing found.’);
}
”
ОWebBrowser.Eval(js)
End Sub
End Class
Javascript is executed by the browser. So I used google and found why your “code” doesn’t work.
https://stackoverflow.com/ questions/3999101 /get-iframes-document-from-javascript-in- main- document
Hi,
“does not work” means what? Do you get an error in the console?
We need a test case with a clear indication of expected result to check this.
Best regards
Frank
Please login first to submit.