views:

33

answers:

0

I try to use the WebBrowserControll with C#. I use the following Code. The WebBrowser Controll open the Web Page and if there is a href= blank it is also oppend in an new WebBrowser Controll. But If I want to open an new JavaScript with window.open it doenst open an new WebBrowser Controll. What I have to do that a href= blank and a Java Script is opend in my WebBrowser Controll.

Does anyone have a Answer??

Thanks for your help.

public MainWindow()
    {
        InitializeComponent();
        webBrowser1.ScriptErrorsSuppressed = true;

        webBrowser1.FileDownload += new  EventHandler(webBrowser1_FileDownload);
        webBrowser1.NewWindow += new CancelEventHandler(webBrowser1_NewWindow);
        webBrowser1.DocumentCompleted +=new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
        webBrowser1.PreviewKeyDown += new PreviewKeyDownEventHandler(webBrowser1_PreviewKeyDown);
        this.FormClosing += new FormClosingEventHandler(webBrowser1_FormClosing);
    }

    public void setURL(String aURL)
    {
            webBrowser1.Url = new Uri(aURL);  
    }

    private void webBrowser1_NewWindow(object sender, CancelEventArgs e)
    {

        // open href= blank  in new WebBrowser Controll
        MainWindow newWindow = new MainWindow();

        newWindow.setURL(webBrowser1.StatusText);
        newWindow.Show();
        e.Cancel = false;       
    }

    private void webBrowser1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
    {
        Console.WriteLine(e.KeyCode.ToString() + "  " + e.Modifiers.ToString());
        if (e.Modifiers == Keys.Control && e.KeyCode == Keys.V)
        {
            MessageBox.Show("ctrl-v pressed");
        }
    }

    private void webBrowser1_FormClosing(object sender, FormClosingEventArgs e)
    {
        if (MessageBox.Show(this, "Really close the window?", "Caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
        {
            e.Cancel = false;
        }
        else
        {
            e.Cancel = true;
        }
    }

    private void beendenToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        this.Close();
    }