C # WebBrowser force to open in this window, disable opening in new window
Sometimes it is necessary to load URLs with WebBrowser to implement certain functions. At this point, we do not want to open the link in the page, open in a new window, because so, in fact, with the system default browser open, and thus out of your webbrowser, it can not be controlled by you.
To work around this problem, you can use the following methods:
Suppose WebBrowser's name is WebBrowser
Simple Method-use the load completion event to change the target value of all links and form to "_self":
private void Webbrowser_documentcompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
// To target all links, point to this form
foreach (HtmlElement archor in this.webBrowser.Document.Links)
{
archor. SetAttribute ("Target", "_self");
}
The submit target for all forms, point to this form
foreach (htmlelement form in this.webBrowser.Document.Forms)
{
form. SetAttribute ("Target", "_self");
}
To cancel a new window event:
private void Webbrowser1_newwindow (object sender, CancelEventArgs e)
{
E.cancel = true;
WebBrowser property setting:
-Set WebBrowser Allowwebbrowserdrop to False (no drag and drop)
-Set WebBrowser webbrowsershortcutsenabled to False (disable use of shortcut keys)
-Set WebBrowser iswebbrowsercontextmenuenabled to False (no right-click context menu)
This article address:http://www.cnblogs.com/atree/archive/2010/09/08/WebBrowser-target_seft_blank.html