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
If you have access to document
and mouse position inside the view you can use document.elementFromPoint(x, y);
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>
-->
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With