如何使用 CEFSHARP 获取 HTML 文档高度?
How to get HTML Document height using CEFSHARP?
我正在更改网络浏览器应用程序以使用基于 CEFSHARP chromium 的浏览器而不是内置的 vb.net 网络浏览器控件,并且需要查询 html 文档才能设置浏览器控制高度为 html 页面的高度。在 VB 网络浏览器控件中,我使用以下设置高度。
WebBrowser.Height = WebBrowser.Document.Body.ScrollRectangle.Height
WebBrowser.Height = WebBrowser.RectangleToScreen
如何在 CEFSHARP 中获取 HTML 文档属性?我一直在寻找线程数,似乎您需要进行 javascript 调用,但我找不到一个简单的示例。任何人都有尝试使用 CEFSHARP 执行此操作的经验吗?
下面是我试图用来获取 HTML 文档高度的代码,但它不起作用。我相当确定它的脚本行是错误的,但似乎无法找到正确的语法来获取文档高度。
Private Sub WWWBrowser_LoadingState(sender As Object, e As LoadingStateChangedEventArgs) Handles WWWBrowser.LoadingStateChanged
If e.IsLoading = False Then
Dim script = "(function() { var body = document.body, html = document.documentElement; return Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); })();"
Dim task As Task(Of JavascriptResponse) = WWWBrowser.EvaluateScriptAsync(script)
Dim taskResult As String
task.ContinueWith(
Sub(t)
If t.IsFaulted = False Then
Dim response = t.Result 'Error: Result is not a member of Task'
If response.Success And response.Result IsNot Nothing Then
taskResult = response.Result
End If
End If
End Sub)
MsgBox(task.Result.Result)
End If
End Sub
我正在更改网络浏览器应用程序以使用基于 CEFSHARP chromium 的浏览器而不是内置的 vb.net 网络浏览器控件,并且需要查询 html 文档才能设置浏览器控制高度为 html 页面的高度。在 VB 网络浏览器控件中,我使用以下设置高度。
WebBrowser.Height = WebBrowser.Document.Body.ScrollRectangle.Height
WebBrowser.Height = WebBrowser.RectangleToScreen
如何在 CEFSHARP 中获取 HTML 文档属性?我一直在寻找线程数,似乎您需要进行 javascript 调用,但我找不到一个简单的示例。任何人都有尝试使用 CEFSHARP 执行此操作的经验吗?
下面是我试图用来获取 HTML 文档高度的代码,但它不起作用。我相当确定它的脚本行是错误的,但似乎无法找到正确的语法来获取文档高度。
Private Sub WWWBrowser_LoadingState(sender As Object, e As LoadingStateChangedEventArgs) Handles WWWBrowser.LoadingStateChanged
If e.IsLoading = False Then
Dim script = "(function() { var body = document.body, html = document.documentElement; return Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight ); })();"
Dim task As Task(Of JavascriptResponse) = WWWBrowser.EvaluateScriptAsync(script)
Dim taskResult As String
task.ContinueWith(
Sub(t)
If t.IsFaulted = False Then
Dim response = t.Result 'Error: Result is not a member of Task'
If response.Success And response.Result IsNot Nothing Then
taskResult = response.Result
End If
End If
End Sub)
MsgBox(task.Result.Result)
End If
End Sub