Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Position of cursor in WKWebView with an editable paragraph in iOS

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

like image 297
papafe Avatar asked Jan 27 '17 11:01

papafe


2 Answers

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

like image 95
Valeria Viana Gusmao Avatar answered Oct 19 '22 17:10

Valeria Viana Gusmao


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>

-->
like image 1
karthik Avatar answered Oct 19 '22 17:10

karthik