launching or and getting url of window.open javascript function of a web site into webBrowser control

marc-antoine yonga 81 Reputation points
2021-05-08T16:04:51.987+00:00

Well,

I would launching or and getting url of window.open javascript function of a web site into webBrowser control prevent the launching into IE window.

I try this and until now, the page is launching into IE window.

I used c#, winform technology and webBrowser System.Windows.Form.

Thanks your for your help.

M.A.

Developer technologies Windows Forms
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2021-05-09T05:57:19.06+00:00

    In order to cancel navigation, you can handle Navigating and NewWindow events and set ‘e.Cancel=True’. You probably are interested in determining the target URL in case of NewWindow event. Check a solution that is based on SHDocVm: https://social.msdn.microsoft.com/forums/en-US/b8878091-8c8f-4460-b457-2a781a2e783b.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. marc-antoine yonga 81 Reputation points
    2021-05-09T07:29:15.043+00:00

    I used the solution of SHDocVm but I've got no result, no showing page.

    See the code that I used, I place the declaration of function in the load Form2 function or and in the function ProgressChanged but for the two choices I've got no result. In the load Form2 function, I've got the error message of null.

    public Form2()
    {
    InitializeComponent();

                ((SHDocVw.DWebBrowserEvents2_Event)webBrowser22.ActiveXInstance).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(MainWindow_NewWindow3);                 
            }
    

    private void toolStripButton4_Click(object sender, EventArgs e)
    {
    webBrowser22.Navigate(toolStripTextBox2.Text);

                            webBrowser22.ProgressChanged += new WebBrowserProgressChangedEventHandler(Browser_ProgressChanged); //this.webBrowser22.Navigating += new WebBrowserNavigatingEventHandler(webBrowser_Navigating);
    

    }

    private void Browser_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
    {

    ((SHDocVw.DWebBrowserEvents2_Event)webBrowser22.ActiveXInstance).NewWindow3 += new SHDocVw.DWebBrowserEvents2_NewWindow3EventHandler(MainWindow_NewWindow3);

        }
    
        void MainWindow_NewWindow3(ref object ppDisp, ref bool Cancel, uint dwFlags, string bstrUrlContext, string bstrUrl)
        {
            webBrowser221.Navigate(bstrUrl);
            Cancel = true;
        }
    

    The page is again launching into IE window.

    Thanks for your help.

    M.A.


  2. Daniel Zhang-MSFT 9,651 Reputation points
    2021-05-10T02:38:34.13+00:00

    Hi marcantoineyonga-1329,
    You can try to use WebBrowser.InvokeScript method to call javascript function.
    And Sam has provided a detailed answer for it in this thread you can refer to.
    Best Regards,
    Daniel Zhang


    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.


  3. marc-antoine yonga 81 Reputation points
    2021-05-10T20:09:12.047+00:00

    Finally, I replace the function NewWindow3 of "SHDocVm" to an other place and the process to open an url in a new page of webBrowser is ok.

    Truly yours.

    M.A.

    0 comments No comments

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.