admin管理员组文章数量:1201569
There seems to be a bug in IE10, where if I place an element over another element with the contenteditable
attribute, the editor's caret is drawn over everything.
You can see this behaviour below in the image below and in this jsFiddle.
I've mucked around with plenty of CSS properties, and been unable to find a solution to this. It works as expected in other browsers.
The reason I need this is because I am designing a WYSWIYG editor (TinyMCE fork) experience where the toolbars slide down over the text when they're required. This bug makes the caret appear over the top of the toolbar.
The only solution I have thought of is to blur the editor's focus, and refocus it when the toolbar has disappeared. However, this will stop users from typing when the toolbar is activated, and would also cause inconsistent behaviour across browsers.
Is there a workaround to this bug?
There seems to be a bug in IE10, where if I place an element over another element with the contenteditable
attribute, the editor's caret is drawn over everything.
You can see this behaviour below in the image below and in this jsFiddle.
I've mucked around with plenty of CSS properties, and been unable to find a solution to this. It works as expected in other browsers.
The reason I need this is because I am designing a WYSWIYG editor (TinyMCE fork) experience where the toolbars slide down over the text when they're required. This bug makes the caret appear over the top of the toolbar.
The only solution I have thought of is to blur the editor's focus, and refocus it when the toolbar has disappeared. However, this will stop users from typing when the toolbar is activated, and would also cause inconsistent behaviour across browsers.
Is there a workaround to this bug?
Share Improve this question asked Apr 4, 2013 at 0:09 alexalex 490k204 gold badges889 silver badges991 bronze badges 9 | Show 4 more comments4 Answers
Reset to default 6 +500There is no way to overlap the caret with another element in IE. This question was asked many times:
- Link 1
- Link 2
...
But you can blur the textarea after getting the caret position (see: Caret position in textarea, in characters from the start) and then show your toolbar. After hiding the toolbar, you can focus the textarea again, setting the caret position with:
function setCaretPosition(elemId, caretPos) {
var elem = document.getElementById(elemId);
if(elem != null) {
if(elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
}
else {
if(elem.selectionStart) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
}
else
elem.focus();
}
}
}
See: Set keyboard caret position in html textbox
Add -ms-user-select: none
to the contenteditable element. Setting focus will then not show the cursor - guessing a browser quirk. Cursor will probably reappear once you hit left/right or type another char though.
You can simulate a caret with JavaScript and CSS and customize it.
With proper customization you can build a practical workaround to this bug.
Here is an interesting article on how to do this:
http://www.dynamicdrive.com/forums/showthread.php?17450-Emulating-a-terminal-like-caret-with-javascript-and-css
Here is a demo:
http://shachi.prophp.org/demo.html
Also, there is a jQuery Terminal Emulator plugin that you can fork and customize to your specific needs:
http://terminal.jcubic.pl/#demo
Well the obvious workaround is to decrease the height of the contenteditable div and show the toolbar above the editable area instead of on top of it.
本文标签:
版权声明:本文标题:javascript - Is there a way to stop a contenteditable's caret from appearing over elements in IE10? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738632718a2103842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
input
elsewhere on the page. – el Dude Commented Apr 4, 2013 at 1:13input
as well; thecontenteditable
attribute isn't needed. That being said, I saw this months ago and never found a solution either. – Sampson Commented Apr 8, 2013 at 2:21