Wisej.Web.WebBrowser.eavl(JS) do not works

0
0

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

 

 

 

 

  • You must to post comments
0
0

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!

 

  • Julie(ITG)
    I tested with your sample, but for me it’s not hitting the js with either button. I put a breakpoint on the eval call (line 262) and it’s not running. Additionally, in the future please include the entire project and not just the Page1.vb file,
  • Julie(ITG)
    The sample works, there is no bug in Wisej. Here are the issues with the sample: 1. Uses static (Shared in VB.NET means static) buttons. Causing the single instance to be shared (as the name Shared implies) therefore the app is unusable in the browser after the first use closes the page. 2.There is nothing wrong in Wisej.NET. The Javascript code runs correctly and it does what it has been programmed for. That is, finds the first element that contains the text “5” and sets the background color to yellow. See what getElementsByTagName(“*”) does and what innerText returns. You can try the js using jsfiddle. Check also mozilla for javascript help. 3.The second sample also works, there is no error at all. The alert is coded in the javascript. And it simply says what it says, that there is no “5” in the second sample.
  • Julie(ITG)
    Additionally- you can’t check the document of an iFrame if the domains don’t match. You would need to host your own version under the same domain.
  • You must to post comments
0
0

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

  • mgmst
    • mgmst
    • Jul 30, 2025 - 3:15 pm
    The problem isn’t with the JavaScript itself, but whether it executes or not. When there are more than 4 nodes, the JavaScript doesn’t run at all. When there are 4 or fewer, it executes and even shows a message. I’m trying to build something like an e-book, with a Table of Contents (TreeView) and positioning to the corresponding chapter when a node is clicked. Nothing complicated. I will prepare a compilable, ready-to-run sample. It will take me a lot of time, but I need a final solution for my e-book.
  • You must to post comments
0
0

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.

  • Julie(ITG)
    Hello, if you can provide a compliable test case we can look into fixing this bug. We would need a compliable test case, not just screenshots or code snippets.
  • You must to post comments
0
0

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

  • mgmst
    • mgmst
    • Jul 30, 2025 - 3:06 pm
    It’s taking me a lot of time, but I’ll get it done. The case is interesting :) I lost two days, 15 hours each, to get to this point.
  • You must to post comments
0
0

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

 

 

 

  • You must to post comments
0
0

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

  • mgmst
    • mgmst
    • Jul 28, 2025 - 5:19 am
    Thank you for your efforts. I can easily fix that. In my case, the problem is that in my BOOKS loading control, the JavaScript doesn’t work at all, whereas in my demo project, it works just fine.
  • You must to post comments
0
0

Nothing at all, complete silence and darkness.

  • JD
    • JD
    • Jul 27, 2025 - 12:21 pm
    Turn the light on?
  • You must to post comments
0
0

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

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.