| <!DOCTYPE html> |
| <meta charset="utf-8"> |
| <div id="container"> |
| <p>مَ متن</p> |
| </div> |
| <div id=log></div> |
| <script> |
| testOffsetFromPoint(container.firstElementChild); |
| |
| function testOffsetFromPoint(element) { |
| var y = element.offsetTop + element.offsetHeight / 2; |
| var xmin = element.offsetLeft; |
| var xmax = xmin + element.offsetWidth; |
| var lastCharacterOffset = null; |
| var results = []; |
| for (var x = xmin - 1; x <= xmax + 1; ++x) { |
| var result = document.caretRangeFromPoint(x, y); |
| var characterOffset = result ? result.startOffset : null; |
| if (characterOffset === lastCharacterOffset) |
| continue; |
| results.push(characterOffset); |
| lastCharacterOffset = characterOffset; |
| } |
| var div = document.createElement("div"); |
| div.innerText = results.join(" "); |
| log.appendChild(div); |
| } |
| |
| if (window.testRunner) { |
| container.style.display = "none"; |
| testRunner.dumpAsText(); |
| } |
| </script> |