I'm trying to capture a text input in a html form in real time in my webview. I'm currently using jquery to capture the text input change and then forward the value through a url that I intercept. I am able to capture each change in the text input but the issue I'm having is my text input loses focus on every new character entered, I have to reclick the text input to continue entering each time (window.location.href causes it to lose focus every time its triggered). Im using the following code:
var form = "
<form class="search_extended">
<input style="" type="text" name="name" id="search_field">
<input type='hidden' name='page' value='name_search'>
</form>"
var script = "
<script type="text/javascript">
$(document).ready(function() {
$("form input, form textarea").on("input propertychange change", function() {
var search_serialized = $(".search_extended").serialize();
window.location.href = "?" + search_serialized;
});});</script>"
script = script + "<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>"
self.webView_Search_Extended.loadHTMLString(form + script, baseURL: nil)
Capture forwarding URL
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
print(request.url?.absoluteString)
var url = request.url?.absoluteString
return true
}