如何填写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("data[body]",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("data[body]",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).更多推荐
发布评论