简体   繁体   English

在contentEditable iframe中获取&设置插入位置(Firefox)

[英]Get & set caret position in contentEditable iframe (Firefox)

I've successfully done this for IE7. 我已经成功地为IE7做了这个。 FF, no dice. FF,没有骰子。

any ideas? 有任何想法吗? Thanks! 谢谢!

var range= window.getSelection().getRangeAt(0);
alert('Current position: '+range.startOffset+' inside '+range.startContainer);
range.setStart(newParent, textOffset);
range.setEnd(newParent, textOffset);

Here's my solution to the OpenWYSIWYG for moving the cursor to a specified position in FireFox, after setting focus to the editor: 这是我的OpenWYSIWYG解决方案,用于在将焦点设置到编辑器后将光标移动到FireFox中的指定位置:

focusEditor: function (n) {
    var editor = this.getEditorWindow(n);

    if (WYSIWYG_Core.isFF) {

        editor.document.body.focus();

        try {
            var sel = this.getSelection(n);
            var range = sel.getRangeAt(0);
            range.setStart(sel.anchorNode.childNodes[0], 1);
            range.setEnd(sel.anchorNode.childNodes[0], 0);
            sel.addRange(range);
        }
        catch (err) {
            //alert(err.description);
        }
    }
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome扩展程序内容可编辑,可获取并设置插入符号 - Chrome Extension contenteditable get and set caret position 获取内容Editable caret position - Get contentEditable caret position 如何在Firefox和旧版IE中的contenteditable div中设置插入符位置 - How to set the caret position in a contenteditable div in Firefox and old IE versions 如何使用contentEditable从iframe中的当前插入位置获取像素偏移量 - How to get the pixel offset from the current caret position in an iframe with contentEditable 在contenteditable div中设置插入符位置 - Set caret position in contenteditable div 如何在 contenteditable 中获取和设置插入符号位置? - How do you get and set the caret position in a contenteditable? 将插入符号位置设置在contenteditable div中的特定位置 - Set caret position at a specific position in contenteditable div 如何在子节点的contenteditable中设置插入符位置? - How to set caret position in contenteditable with childs nodes? 如何在contentedable span中设置插入位置然后发送Keys? - How to set caret position in contenteditable span and then sendKeys? 在有孩子的 'contenteditable' div 中设置插入符号 Position - Set Caret Position in 'contenteditable' div that has children
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM