C # WebBrowser force to open in this window, disable opening in new window

Source: Internet
Author: User
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

Related Article

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.