InvokeScript("eval",args) on webview2

younes abdella 1 Reputation point
2021-03-03T17:45:07.953+00:00

i will try execute eval javascript on webview2 wpf project , on webroser worke fine InvokeScript("eval",args) but in webview2 not woke plz can you help me .

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,671 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,245 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Cheong00 3,471 Reputation points
    2021-03-04T01:39:21.96+00:00

    Try use the code provided in this answer instead.

    0 comments No comments

  2. DaisyTian-1203 11,616 Reputation points
    2021-03-04T09:27:57.27+00:00

    The old one which is named WebView has InvokeScript method, but there is no method in WebView2 Class Method like InvokeScript in WebBrowser Class Method and WebView Class Method. You can use WebView2.ExecuteScriptAsync(String) Method to execute JavaScript code from the javaScript parameter in the current top level document rendered in the WebView. To include the args for the eval, you can use it as below:
    74573-capture.png

    By the way, you can create your custom InvokeScript method referring to cheong00's reply.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments