下面是我用来改变IE中显示的HTML的代码。但是,它总是抛出异常-无法设置outerHTML属性。此操作的目标元素无效。不能设置outerHTML吗?
protected void AlterContent(ref HTMLDocument docInput, HTMLDocument docAlteredOutPut)
{
try
{
if (docInput.body.tagName.ToLower() == "body" && docAlteredOutPut.body.innerHTML != null)
{
docInput.documentElement.outerHTML = docAlteredOutPut.documentElement.outerHTML;
}
}
catch
{
}
}谢谢。
发布于 2011-05-08 20:45:23
不能替换<body>元素的html。不需要这样做,这可以很好地工作:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
webBrowser1.Url = new Uri("http://stackoverflow.com");
webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
var body = webBrowser1.Document.Body;
body.InnerHtml = "pwned";
}
}https://stackoverflow.com/questions/5927254
复制相似问题