windows.opener() handling with WebView2

Neha 20 Reputation points
2025-01-13T06:37:06.7133333+00:00

In the webform, I have used window.opener for opening a new window that acted as a dialog which required user input, and needed to pass information back to the main window. I am trying to embed this in winform using WebView2 control.The NewWindowRequested eventhandler is supporting windows.open() in a new tab (e.handled=true) .But the windows.opener() is not working as expected.Which event handler can I use for implementing this functionality?Thanks in advance!

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,917 questions
Universal Windows Platform (UWP)
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.
11,195 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiale Xue - MSFT 48,686 Reputation points Microsoft Vendor
    2025-01-13T07:54:34.9133333+00:00

    Hi @Neha , Welcome to Microsoft Q&A,

    One of the solutions is similar to what you said about "closing". You can define a callback method through the parent window, and the child window calls this method when it is closed to pass the selected data back.

    If the interaction scenario is fixed, this method is simpler. It requires custom events; data is passed only when the child window is closed.

    If you need to process JSON messages and WebView2 supports WebMessage, you can use WebMessage to process dynamic pages and complex interactions without changing the page logic. You can execute JavaScript through ExecuteScriptAsync to actively send data to the page.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.