question

marcantoineyonga-1329 avatar image
0 Votes"
marcantoineyonga-1329 asked marcantoineyonga-1329 answered

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

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.

windows-forms
5 |1600 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.

Viorel-1 avatar image
0 Votes"
Viorel-1 answered

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.


5 |1600 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.

marcantoineyonga-1329 avatar image
0 Votes"
marcantoineyonga-1329 answered marcantoineyonga-1329 commented

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.

· 1
5 |1600 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.

I change the function "progress" by a function" navigating" as :

private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e){ }

and I put e.Ccancel to true but I've got no result and it's always IE explorer that is launching.

Thanks you.

M.A.

0 Votes 0 ·
DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered marcantoineyonga-1329 commented

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.


· 1
5 |1600 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.

I tried the solution of used webBrowser.InvokeScript but it is not interessant because javascript of the site is functionnal and that execute the code but doesn't redirect the url to webBrowser control. the click is known by webBrowser but the problem is that the function window.open of the button opens an IE window instead of webBrowser window so there must be a solution to intercept and redirect the ur l of window.open to webBrowser control.
Thanks you for your help. M.A.

0 Votes 0 ·
marcantoineyonga-1329 avatar image
0 Votes"
marcantoineyonga-1329 answered

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.

5 |1600 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.