2013-08-18 20 views
0

我有一個iframe文本編輯器。對於插入圖像,我有一段代碼:在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,但它似乎沒有工作。在插入之前插入所選內容或與其相鄰的元素之前插入。任何方式讓它插入後。這樣,它看起來好像用戶如果從右到左打字而不是從左到右

回答

0

我會盡量避免使用iframe。有沒有一種方法可以用div實現你的目標,或者使用JQuery調用AJAX?這不完全是你所說的,但你可以對你的所見即所得編輯器使用同樣的想法。 http://techmeout.org/hacking-joomla/

相關問題