Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何获得iframe中的字符偏移?_Javascript_Html_Iframe - Fatal编程技术网

Javascript 如何获得iframe中的字符偏移?

Javascript 如何获得iframe中的字符偏移?,javascript,html,iframe,Javascript,Html,Iframe,#textEditor是我在代码中使用的iframe的id 编辑:以x-y坐标表示的偏移量,而不是从iframe开始的字符数 提前感谢。您是指从输入开始的字符数偏移量,还是文档中x-y坐标的偏移量?@Frist Van Campen offset in x-y坐标。 $(document).ready(function () { $('#textEditor').contents().keypress(function (e) { if (e.which == 35) {

#textEditor
是我在代码中使用的iframeid

编辑:以x-y坐标表示的偏移量,而不是从iframe开始的字符数


提前感谢。

您是指从输入开始的字符数偏移量,还是文档中x-y坐标的偏移量?@Frist Van Campen offset in x-y坐标。
$(document).ready(function () {
    $('#textEditor').contents().keypress(function (e) {
        if (e.which == 35) {
            alert('# pressed');
            //How to get '#' character offset relative to an iframe
        }
        return true;
    });
var selection = window.getSelection();
var range = selection.getRangeAt(0);
console.log(range.getBoundingClientRect()); // left, top, height, width