33

Is there anyway to get the position of the cursor in a WKWebView in iOS that contains an editable paragraph (a paragraph with attributed contentEditable set to true)?

EDIT: To add additional information, the editable div can contain other subnodes

papafe
  • 2,959
  • 4
  • 41
  • 72

2 Answers2

1

If you have access to document and mouse position inside the view you can use document.elementFromPoint(x, y);

1

This can be done in multiple ways using HTML5 (using autofocus atribute) or using javascript (document.getElementById("IDHERE").focus(); - using focus event). I will write all in one code snippet uncomment and use it based on your requirement.

//if u commnet the second form 
let domObject =  document.getElementById("lname"); // refer which object to focus
domObject.focus(); // event to trigger focus on the refereced dom object  

//throw error till second form is uncommented
<!-- html5 way the most easiest way -->

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname" autofocus><br>
  <input type="submit">
</form>

<!-- autofocus refers where to focus -->
<!-- unncoment below and comment above -->
<!-- javascript way -->

<!-- 
<form action="/action_page.php">
  First name: <input type="text" id="fname"><br>
  Last name: <input type="text" id="lname"><br>
  <input type="submit">
</form>

-->
Vega
  • 27,856
  • 27
  • 95
  • 103
karthik
  • 1,100
  • 9
  • 21