在Iframe文本编辑器中插入After



我有一个iframe文本编辑器。对于插入图像,我有一段代码如下:

.
.
.
  var sel = document.getElementById('wysiwygtextfield').contentWindow.getSelection();
  // get the first range of the selection (there's almost always only one range)
  var range = sel.getRangeAt(0);
  // deselect everything
  sel.removeAllRanges();
  // remove content of current selection from document
  range.deleteContents();
  // get location of current selection
  var container = range.startContainer;
.
.
.
 **afterNode = container.childNodes[0];
 container.insertBefore(insertNode, afterNode);**
 // This does not work
 // container.insertAfter(insertNode, afterNode);

问题出在最后两行。我试过使用insertAfter,但似乎不起作用。带有insert before,它在选定内容或与其相邻的元素之前插入。任何使它在之后插入的方法。通过这种方式,它看起来就像用户从右到左键入而不是从左到右键入

我会尽量避免使用iframe。有没有一种方法可以通过div或使用JQuery的AJAX调用来实现您的目标?这并不完全是你所说的,但你可以对你的所见即所得编辑器使用同样的想法。http://techmeout.org/hacking-joomla/

最新更新