admin管理员组文章数量:1023848
How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).
How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).
Share Improve this question edited Mar 3, 2019 at 10:20 Cœur 38.8k25 gold badges206 silver badges279 bronze badges asked Nov 11, 2010 at 9:46 user495688user495688 9632 gold badges15 silver badges26 bronze badges4 Answers
Reset to default 3You've asked about selection coordinates twice before. I know I've given you a working answer, so why are you asking again?
Here's some code that will return you the innermost element containing the selection in Firefox (assuming a single selection; Firefox allows multiple selections). Hope it's helpful.
function getSelectionContainerElement() {
var sel = window.getSelection(), el = null;
if (sel.rangeCount) {
var range = sel.getRangeAt(0);
el = range.monAncestorContainer;
if (el.nodeType != 1) {
el = el.parentNode;
}
}
return el;
}
refer the getSelection(), to get an object which contains information about the selected text and its position in the parent Element
Selection - MDC
might help you to find answer of all your questions.
You can find the exact answer here
but this module is under construction, You can browse project and find this module.
How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).
How to select the text of the page in FireFox? For example, there's a paragraph of text, user select the text in those paragraph in a regular way.then, I want to know in which paragraph the text selected by user (in which position-xy coordinates, range position).
Share Improve this question edited Mar 3, 2019 at 10:20 Cœur 38.8k25 gold badges206 silver badges279 bronze badges asked Nov 11, 2010 at 9:46 user495688user495688 9632 gold badges15 silver badges26 bronze badges4 Answers
Reset to default 3You've asked about selection coordinates twice before. I know I've given you a working answer, so why are you asking again?
Here's some code that will return you the innermost element containing the selection in Firefox (assuming a single selection; Firefox allows multiple selections). Hope it's helpful.
function getSelectionContainerElement() {
var sel = window.getSelection(), el = null;
if (sel.rangeCount) {
var range = sel.getRangeAt(0);
el = range.monAncestorContainer;
if (el.nodeType != 1) {
el = el.parentNode;
}
}
return el;
}
refer the getSelection(), to get an object which contains information about the selected text and its position in the parent Element
Selection - MDC
might help you to find answer of all your questions.
You can find the exact answer here
but this module is under construction, You can browse project and find this module.
本文标签: javascriptget range and coordinate of selected textStack Overflow
版权声明:本文标题:javascript - get range and coordinate of selected text - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745560226a2156118.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论