webbrowser help
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?
Ryan LPosted Nov 19, 2008, 1:51 AM
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 < and > because this post was interpreting the html I was trying to show