本文介绍了是否可以在csharp中设置externalHTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


以下是我用来更改IE中显示的html的c#代码.但是,它总是抛出异常-无法设置externalHTML属性.此操作的目标元素无效.无法设置externalHTML吗?

Hi,
Below is the c# code i use to alter the html displayed in IE. However it always throws exception - Could not set the outerHTML property. Invalid target element for this operation. Is it not possible to set the 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 (Exception ex)
    {
    }
}



谢谢,Arun



Thanks, Arun

推荐答案

bool startFromScratch = false;

//...

startFromScratchButton.Click += (sender, eventArgs) => {
   startFromScratch = true;
   webBrowser.Navigate((Uri)null); //navigate to empty   
} //startFromScratchButton.Click

webBrowser.Navigated += (sender, eventArgs) => {
   if (startFromScratch) {
      var document = webBrowser.Document;
      var body = document.Body;
      document.Body.InnerHtml = "<p>some paragraph content</p>";
   } //if
}; //webBrowser.Navigated



我测试过了.

—SA



I tested it.

—SA


这篇关于是否可以在csharp中设置externalHTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 19:37