Sometimes you need to load a URL with WebBrowser to implement some functionality. At this point, we do not want to open the page in the link, opened in a new window, because in this case, the system is actually opened with the default browser, so that out of your webbrowser, it can not be controlled by you.
To solve this problem, you can use the following method:
The first solution should be recommended to use
[Code=csharp] private void Webbrowser1_newwindow (object sender, CancelEventArgs e)
{
String url = ((WebBrowser) sender). StatusText;
WebBrowser1.Navigate (URL);
E.cancel = true;
}[/code]
StatusText is the URL to jump to
E.cancel = true; is cancel new window open,
The second method of
Suppose WebBrowser's name is WebBrowser1.
Simple method-Use the load completion event to change the target value of all links and form to "_seft":
[Code=csharp]private void Webbrowser1_documentcompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
Target all the links, point to this form
foreach (HtmlElement archor in This.webBrowser1.Document.Links)
{
Archor. SetAttribute ("Target", "_self");
}
Put all of the form's submission targets, pointing to this form
foreach (HtmlElement form in this.webBrowser1.Document.Forms)
{
Form. SetAttribute ("Target", "_self");
}
}
Set the Allowwebbrowserdrop of WebBrowser to False (no drag and drop)
Set the webbrowsershortcutsenabled of WebBrowser to False (disable the use of shortcut keys) to set the iswebbrowsercontextmenuenabled of WebBrowser to False (disable right-click Context menu)
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.