Open new page in WebBrowser

Source: Internet
Author: User

A few days ago to write the online booking auxiliary system, logistics group feedback If you encounter an unexpected situation, the site pop-up Interactive new window, but the content is not seen. After the test found that the new window is open in IE, and the current session lost contact, so require the login, the process can not continue, to solve this problem, You must require that the newly opened Web page be controlled by WebBrowser.

To solve this problem, first Baidu after Google, found that a lot of people are asking, but the solution is mostly unreliable, or vague, or irrelevant, finally found an article to solve the problem. In view of the universality of the problem, I also listed the solution so that netizens can search more help.

The solution is simple, in two cases, one is to open a new page in the current WebBrowser, and the other is to open a new page in the WebBrowser in the new form:

Public Form1 ()
{
InitializeComponent ();

This.webBrowser1.AllowWebBrowserDrop = false; Can be set in properties, it's important


Open in WebBrowser in the new form
(This.webBrowser1.ActiveXInstance as Shdocvw.webbrowser). NewWindow2 + = new Shdocvw.dwebbrowserevents2_newwindow2eventhandler (FORM1_NEWWINDOW2);

Open in main webbrowser
(This.webBrowser1.ActiveXInstance as Shdocvw.webbrowser). NEWWINDOW3 + = new Shdocvw.dwebbrowserevents2_newwindow3eventhandler (FORM1_NEWWINDOW3);
}

void Form1_newwindow2 (ref object PPDISP, ref bool Cancel)
{
FORM5 frm = new FORM5 (); Build a form with WebBrowser in advance
Ppdisp = frm.webBrowser1.ActiveXInstance;
frm. Show ();
}

void Form1_newwindow3 (ref object PPDISP, ref bool Cancel, UINT dwflags, String bstrurlcontext, String bstrurl)
{
Cancel = true;
This.webBrowser1.Navigate (bstrURL);
}

Then, if you open a new page in a new window, the main page and the new page can interact with each other in the same session.

Another: SHDocVw.dll in C:/windows/system32, to refer to the project, this is the basis, should not have questions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.