如何填写javascript编辑器?(How do I fill a javascript editor?)

编程入门 行业动态 更新时间:2024-10-25 08:19:38
如何填写javascript编辑器?(How do I fill a javascript editor?)

我使用TEmbeddedWebBrowser使用FillForm方法填充html表单。 但我的html表单包含一个完全基于javascript的编辑器,我不知道如何填写它。

像这样的东西:

your comment : <script type='text/javascript' src='public/scripts/src/editor.js?1'></script>

提交btton:

<input type="submit" name="btnSubmit" id="btnSubmit" value="Send" class="btn" onclick="rtevalue(&quot;data[body]&quot;,437934);" />

I use TEmbeddedWebBrowser to fill a html form using FillForm method. But my html form contains a fully javascript based editor and i don't know how to fill that.

Something like this :

your comment : <script type='text/javascript' src='public/scripts/src/editor.js?1'></script>

And the submit btton :

<input type="submit" name="btnSubmit" id="btnSubmit" value="Send" class="btn" onclick="rtevalue(&quot;data[body]&quot;,437934);" />

最满意答案

编辑器本身是DIV (可以是其他HTML元素)或IFRAME设置为contentEditable / designMode = on 。 如果元素是DIV您可以使用它的InnerHTML属性。 要使用IFRAME获得最佳效果,请使用以下代码:

procedure TForm1.Button1Click(Sender: TObject); var editorDoc: OleVariant; range: OleVariant; id: OleVariant; begin id := 'editor'; // frame ID editorDoc := (WebBrowser1.Document as IHTMLDocument2).parentWindow.frames.item(id).Document; range := editorDoc.body.createTextRange(); // range.collapse(false); // if you need to append range.select(); range.pasteHTML('<b>Boo!</b>'); end;

笔记:

没有错误检查来简化代码。 您也可以尝试使用range.execCommand('inserthtml', false, MyText) (未使用TEmbeddedWebBrowser进行测试,但在IE上使用纯HTML / Javascript进行测试时TEmbeddedWebBrowser了虚假结果)。

The editor itself is a DIV (could be other HTML element) or IFRAME set to contentEditable / designMode = on. If the element is a DIVyou could use it's InnerHTML property. For the best results with an IFRAME use the below code:

procedure TForm1.Button1Click(Sender: TObject); var editorDoc: OleVariant; range: OleVariant; id: OleVariant; begin id := 'editor'; // frame ID editorDoc := (WebBrowser1.Document as IHTMLDocument2).parentWindow.frames.item(id).Document; range := editorDoc.body.createTextRange(); // range.collapse(false); // if you need to append range.select(); range.pasteHTML('<b>Boo!</b>'); end;

Notes:

No error checking to simplify the code. You might also try range.execCommand('inserthtml', false, MyText) (Not tested with TEmbeddedWebBrowser, but had bogus results when I tried it with plain HTML/Javascript on IE).

更多推荐

本文发布于:2023-08-07 15:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   javascript   editor   fill

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!