Skip to content

Webbrowser help

Ryan L

Asked Nov 18, 2008, 7:21 PM EST1 answer
Share
LinkedInX
Hey all, I am using the webbrowser component for a program I am working on. I am generating the html within the program to display. It works for the first load, however when i click a link to generate new html within my program, i get a script error and the new html does not load. How can i clear the webBrowser1.documentText and insert new html for it to load?

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • +1
    Ok, I have successfully been able to clear the documenttext to load new html, however, I still cannot use the onclick of a link to load new html. I can do anything else such as load a message box or anything of the sort but can not load the new html page. This is the error that I get when i click the link

    Error: Object doesnt support this property or method

    here is what my program is so far:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Security.Permissions;

    namespace Cooking
    {
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    [System.Runtime.InteropServices.ComVisibleAttribute(true)]

    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }
    public void Test(String message)
    {
    MessageBox.Show(message, "client code");
    }

    private void ChangeHtml(string htmlIn)
    {
    webBrowser1.Document.OpenNew(true);
    webBrowser1.Document.Write(htmlIn);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
    webBrowser1.AllowWebBrowserDrop = false;
    webBrowser1.IsWebBrowserContextMenuEnabled = false;
    webBrowser1.WebBrowserShortcutsEnabled = false;
    webBrowser1.ObjectForScripting = this;
    //webBrowser1.Navigate("about:blank");
    //ChangeHtml("a href=\"\" onclick=\"window.external.Test('Changed the page finally'); return false\"Click here/a");
    webBrowser1.DocumentText = "html body a href='' onclick='window.external.GetHtml(\"something\"); return false'Click here /a /body /html>";
    //ChangeHtml("a href=\"\" onclick=\"window.external.GetHtml('something'); return false\"Click here/a");
    }

    private void GetHtml(String str)
    {
    switch (str)
    {
    case "test":
    ChangeHtml("FINALLY GOT THE PAGE TO CHANGE!!!");
    break;
    case "something":
    ChangeHtml("a href=\"www.google.com\"Google/a");
    break;
    }
    }

    private void button1_Click(object sender, EventArgs e)
    {
    ChangeHtml("Whatever");
    }
    }
    }


    I had to leave out the because this post was interpreting the html I was trying to show
    +1