简体   繁体   English

返回插入符位置或IE8中的div范围

[英]Return caret postion or range of a div in IE8

I am wanting to return the start and end range or the caret postion inside a div. 我想返回div内的开始和结束范围或插入符号位置。 The div will have the attribute contentEditable. div将具有属性contentEditable。

typically I would use document.selection.createRange(); 通常我会使用document.selection.createRange(); but the createRange function is broken in IE8 is there a way to get around this? 但是createRange函数在IE8中坏了,有没有办法解决这个问题?

Your description is a bit vague, but this might help: 您的描述有点含糊,但这可能会有所帮助:

If your editor consists of two documents (one containing toolbars and one containing the content of your document), you need to call document.focus() on the window object containing the content-document. 如果您的编辑器由两个文档组成(一个包含工具栏,一个包含文档内容),则需要在包含内容文档的窗口对象上调用document.focus()。

See here for a similar case: Changes to selection and range functionality in IE8 参见以下类似案例: IE8中选择和范围功能的更改

document.selection.createRange(); works the same in IE 8 as it did in versions 7, 6, 5 and 4. If you mean you want an object that works like a DOM Range , as all other mainstream browsers have, I'd suggest using IERange , which creates Range -like objects from IE's TextRange s. 在IE 8中的工作方式与版本7、6、5和4中的工作方式相同。如果您要的是一个像DOM Range一样工作的对象,就像所有其他主流浏览器一样,我建议您使用IERange ,它可以创建Range IE的TextRange的类对象。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM