我試圖讓WkWebView在WkWebView發送包含網頁的JavaScript函數調用後以編程方式打開電話文本輸入鍵盤。WkWebView無法打開輸入字段的鍵盤
此調用激活某個輸入(id:activeElementToShowKeyboard)後,出於效率原因,我希望鍵盤顯示前一個tel輸入(id:numberInput)。
元素永遠不會獲得焦點並打開鍵盤。
我明白爲什麼當一個元素請求焦點時鍵盤不會自動打開,但我猜想必須有一種方法來做到這一點。
我試過了(沒有運氣): click(); focus(); click()。focus(); FastClick jGestures
下面是一個將在本地運行的示例。在chrome的開發者控制檯中,你可以輸入FunctionCalledByWkWebView(「text」);它會工作,但在iOS上,鍵盤將永遠不會在註釋掉的警報下打開。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=0">
<meta name="format-detection" content="telephone=no" />
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
</head>
<body>
<div>
<input type="text" class="active target" />
<input type="text" class="target" />
<input type="tel" id="numberInput" />
<input type="text" class="target" id="activeElementToShowKeyboard" />
</div>
<style type="text/css">
.active {
background-color: red;
}
</style>
<script type="text/javascript">
$(".target").focusin(function() {
$(".active").removeClass("active");
$(this).addClass("active");
});
function FunctionCalledByWkWebView(someText) {
var $selected = $(".active").removeClass("active");
$selected.val(someText);
var divs = $(".target");
var newActiveElement = divs.eq((divs.index($selected) + 1) % divs.length).addClass("active");
if ($(newActiveElement).is("#activeElementToShowKeyboard")) {
//alert("Should bring up keyboard!");
$("#numberInput").focus();
}
}
</script>
</body>
</html>
我針對所有iOS設備,主要是iPod touch上(第五/第六代)或iPhone 6.我測試在iOS 8.4
人有什麼想法?
在iOS上10,這是導致鍵盤出現,任何想法,爲什麼? –
這使得鍵盤出現,因爲網頁正在調用焦點在一個領域,所以它就像在領域輕拍,這是swizzle的點。 – hawkeyecoder