question

younesabdella-5154 avatar image
0 Votes"
younesabdella-5154 asked ·

InvokeScript("eval",args) on webview2

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 .

dotnet-csharpwindows-wpf
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cheong00 avatar image
0 Votes"
cheong00 answered ·

Try use the code provided in this answer instead.


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DaisyTian-MSFT avatar image
0 Votes"
DaisyTian-MSFT answered ·

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.



capture.png (8.1 KiB)
capture.png (7.2 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.