InvokeScript("eval",args) on webview2

younes abdella 1 Reputation point

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,700 questions
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,524 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Cheong00 3,471 Reputation points

    Try use the code provided in this answer instead.

    0 comments No comments

  2. DaisyTian-1203 11,616 Reputation points

    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:

    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