使用 WebBrowser 控件作为编辑器时出现问题

发布于 2024-08-31 08:00:06 字数 455 浏览 6 评论 0原文

我目前正在开发一个项目,其中使用 WebBrowser 控件作为编辑器。我打开了设计模式,它似乎正在工作。我遇到的问题是,当我尝试保存文档并加载另一个文档时,它会弹出“此文档已被修改”。信息。我想做的就是这么简单,

if (frontPage)
{
    frontPage = false;
    frontContent = webEditor.DocumentText;
    webEditor.DocumentText = backContent;
}
else
{
    frontPage = true;
    backContent = webEditor.DocumentText;
    webEditor.DocumentText = frontContent;
}

就像我说的那样,每次我输入一些文本并运行此代码时,它都会弹出一条消息,说它已被修改,并询问我是否要保存。我该如何解决这个问题?

I am currently working on a project where I am using a WebBrowser control as an editor. I have design mode turned on and it seems to be working. The issue im having is when I try to save the Document and load another it pops up the "This document has been modified." message. What I am trying to do is as simple as this

if (frontPage)
{
    frontPage = false;
    frontContent = webEditor.DocumentText;
    webEditor.DocumentText = backContent;
}
else
{
    frontPage = true;
    backContent = webEditor.DocumentText;
    webEditor.DocumentText = frontContent;
}

Like I said everytime I enter some text and run this code it just pops up a message saying its been modified and asks if I want to save. How can I get around this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

泪冰清 2024-09-07 08:00:06

您应该创建以下函数:

void ChangeAllowWebBrowserDrop() { webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop; }

每次更改 DocumentText 之前都应该调用它。

You should create the following function:

void ChangeAllowWebBrowserDrop() { webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop; }

It should be called every time before you change DocumentText.

自由范儿 2024-09-07 08:00:06

你可以

BodyHtml.  

这样设置:

string newHTMLString="some html";
webBrowser1.Document.Body.InnerHtml = newHTMLString;

Worked for me 。

You could set

BodyHtml.  

Like this:

string newHTMLString="some html";
webBrowser1.Document.Body.InnerHtml = newHTMLString;

Worked for me .

救赎№ 2024-09-07 08:00:06

您应该创建以下函数:

void ChangeAllowWebBrowserDrop() {
    webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop;
}

每次更改 DocumentText 之前都应该调用它。

You should create the following function:

void ChangeAllowWebBrowserDrop() {
    webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop;
}

It should be called every time before you change DocumentText.

善良天后 2024-09-07 08:00:06

更好的解决方案是在实际分配 html 代码之前写入空字符串:
WebBrowser1.Document.Write(string.Empty);
WebBrowser1.DocumentText = "您的代码";

better solution is to write empty string before you actually assign your html code:
WebBrowser1.Document.Write(string.Empty);
WebBrowser1.DocumentText = "your code";

︶葆Ⅱㄣ 2024-09-07 08:00:06

我已经解决了这个问题:

browser.Document.Write(string.Empty);  
browser.DocumentText="Your html code"; 

这是来自这个链接:
http:// /social.msdn.microsoft.com/Forums/vstudio/en-US/3a9c1965-8559-4972-95e1-da0e86cf87bb/webbrowser-strange-problem

I have solved this problem so:

browser.Document.Write(string.Empty);  
browser.DocumentText="Your html code"; 

This is from this link:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/3a9c1965-8559-4972-95e1-da0e86cf87bb/webbrowser-strange-problem

凉世弥音 2024-09-07 08:00:06

Windows 窗体加载文档流(由 DocumentText 属性使用)的方式是导航到 about:blank,这将触发文档修改消息,然后在其 DocumentComplete 事件处理程序中加载该流。

由于您已经有一个文档,因此您可以跳过导航并直接通过其 IPersistStreamInit 接口将流加载到现有文档中,就像 Windows 窗体在其 DocumentComplete 事件处理程序中所做的那样。

The way Windows Forms load a document stream (used by the DocumentText property) is to navigate away to about:blank, which triggers the document modified message, then load the stream in its DocumentComplete event handler.

Since you already have a document, you can skip the navigation and load the stream into the existing document directly via its IPersistStreamInit interface like Windows Forms does in its DocumentComplete event handler.

挽袖吟 2024-09-07 08:00:06

试试这个 webEditor.ScriptErrorsSuppressed = true;

确保您已在 IE 中禁用脚本调试(如果您已打开它)。

Try this webEditor.ScriptErrorsSuppressed = true;

Make sure you have disabled Script Debugging in IE in case you've turned it on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文