The web browser control supports the NewWindow event to receive pop-up notification. However, the Winforms shell does not allow you to do much, you can only cancel the pop-up window. Own COM-shell allows you to transfer a new instance of a web browser, this instance will then be used to display a pop-up window.
Using this requires some work. First, use the link "Project + Add Link", "Browse" and select c: \ windows \ system32 \ shdocvw.dll. This adds a link to the native COM interface.
Create a form that acts as a popup form. Drop the WebBrowser on it and make its code look like this:
public partial class Form2 : Form {
public Form2() {
InitializeComponent();
}
public WebBrowser Browser {
get { return webBrowser1; }
}
}
Browser , - .
. WebBrowser :
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
webBrowser1.Url = new Uri("http://google.com");
}
SHDocVw.WebBrowser nativeBrowser;
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
nativeBrowser = (SHDocVw.WebBrowser)webBrowser1.ActiveXInstance;
nativeBrowser.NewWindow2 += nativeBrowser_NewWindow2;
}
protected override void OnFormClosing(FormClosingEventArgs e) {
nativeBrowser.NewWindow2 -= nativeBrowser_NewWindow2;
base.OnFormClosing(e);
}
void nativeBrowser_NewWindow2(ref object ppDisp, ref bool Cancel) {
var popup = new Form2();
popup.Show(this);
ppDisp = popup.Browser.ActiveXInstance;
}
}
OnLoad COM-, NewWindow2. FormClosing, 100% , . , .
NewWindow2 , , . . Form2 Show(). Show(), , . , , MDI .
, , , Javascript alert(). HTML , .