I use WebBrowser
control and have text inside like:
some text https://www.example.com some text.
This is my code the way I added the text and enabled the web browser to edit contents:
public partial class Form1 : Form
{
private HTMLBody _body;
public Form1()
{
InitializeComponent();
webBrowser1.Navigate("about:blank");
}
private void webBrowser1_DocumentCompleted(object sender,
WebBrowserDocumentCompletedEventArgs e)
{
_body = ((HTMLBody)((HTMLDocument)webBrowser1.Document.DomDocument).body);
_body.contentEditable = true.ToString();
_body.innerHTML = "some text https://www.example.com some text";
}
}
If I run it and changed part of link (for type something else instead of 'example.com' and lost focus) then it automatically adds tag <a>
around my link. You can see it in innerHTML property. But it's wrong for me.
Is there a way to avoid to do this behavior? Thanks a lot!
答案 0 :(得分:0)
您可以在文档中关闭自动提示网址。为此,在为body设置新内容后,在DocumentCompleted
evnet中添加以下代码行:
webBrowser1.Document.ExecCommand("AutoUrlDetect", false, false);
此外,您可以在不添加mshtml.dll
引用的情况下编辑内容。为此,您只需使用:
this.webBrowser1.DocumentText = @"<HTML><BODY contentEditable=""true""></BODY></HTML>";