使用CEFSHARP逃脱JavaScript和HTML字符串

发布于 2025-02-12 02:22:06 字数 1464 浏览 1 评论 0原文

上下文:

我想使用嵌入Tinymce JS的CEFSHARPBROWSER加载HTML代码。

正确执行此操作的方法是:

Dim browser As ChromiumWebBrowser
Dim strHTMLPageCode As String = "<p>Hello</p>"
browser.GetMainFrame.ExecuteJavaScriptAsync("tinymce.activeEditor.setContent('" & strHTMLPageCode & "');"))

问题:

当strhtmlpagecode获得“真实” html(带有line feed,tag等)时,它不起作用,例如

<html>
  <head>
    <title>Href Attribute Example</title>
  </head>
  <body>
    <h1>Href Attribute Example</h1>
    <p>
      <a href="https://www.freecodecamp.org/contribute/">The freeCodeCamp Contribution Page</a> shows you how and where you can contribute to freeCodeCamp's community and growth.
    </p>
  </body>
</html>

,我必须逃脱字符串。

我尝试过

browser.GetMainFrame.ExecuteJavaScriptAsync("tinymce.activeEditor.setContent('" & HttpUtility.HtmlEncode(strHTMLPageCode) & "');"))
browser.GetMainFrame.ExecuteJavaScriptAsync(HttpUtility.Javascriptencode("tinymce.activeEditor.setContent('" & HttpUtility.HtmlEncode(strHTMLPageCode) & "');")))
browser.GetMainFrame.ExecuteJavaScriptAsync(HttpUtility.JavaScriptStringEncode("tinymce.activeEditor.setContent('") & HttpUtility.HtmlEncode(strHTMLPageCode) & "');")

这些都没有用。

Context:

I want to load HTML code using a CEFSharpBrowser embedding a TinyMce JS.

The correct way to do it is:

Dim browser As ChromiumWebBrowser
Dim strHTMLPageCode As String = "<p>Hello</p>"
browser.GetMainFrame.ExecuteJavaScriptAsync("tinymce.activeEditor.setContent('" & strHTMLPageCode & "');"))

Issue:

It doesn't work when strHTMLPageCode got "real" html (with line feed, tags, etc) e.g.

<html>
  <head>
    <title>Href Attribute Example</title>
  </head>
  <body>
    <h1>Href Attribute Example</h1>
    <p>
      <a href="https://www.freecodecamp.org/contribute/">The freeCodeCamp Contribution Page</a> shows you how and where you can contribute to freeCodeCamp's community and growth.
    </p>
  </body>
</html>

So, i had to escape the string.

I tried

browser.GetMainFrame.ExecuteJavaScriptAsync("tinymce.activeEditor.setContent('" & HttpUtility.HtmlEncode(strHTMLPageCode) & "');"))
browser.GetMainFrame.ExecuteJavaScriptAsync(HttpUtility.Javascriptencode("tinymce.activeEditor.setContent('" & HttpUtility.HtmlEncode(strHTMLPageCode) & "');")))
browser.GetMainFrame.ExecuteJavaScriptAsync(HttpUtility.JavaScriptStringEncode("tinymce.activeEditor.setContent('") & HttpUtility.HtmlEncode(strHTMLPageCode) & "');")

None of these worked.

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

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

发布评论

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

评论(1

独自唱情﹋歌 2025-02-19 02:22:06

问题在于HTML字符串,该字符串具有“非规则”线供稿。
我能够看到此问题,这要归功于开发器控制台,这要感谢:
browser.showdevtoolsdocked(me)

The issue was in the html string which had "non regular" line feed.
I was able to see this issue thanks to the developper console, displayable thanks to :
browser.ShowDevToolsDocked(Me)

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