Dav*_*lle 10 javascript keyboard iframe events mobile-safari
在我的网络应用程序中,我有不同z-indices的iframe.我正在检测touchstart
iframe中某些元素的事件.但是,如果我的文本输入字段与元素捕获重叠touchstart
,则输入字段开始表现不正常:在字段中第二次点击未聚焦它,您无法选择任何文本,但您可以键入文本领域.
似乎唯一的解决方案可能是停止touchstart
在背景帧上捕获事件.我更喜欢像透明的解决方案div
来捕捉事件作为中间人,但我还没有得到这个工作.还有其他解决方法吗?
示例页面位于jsfiddle,但这里是代码:
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
iframe {
position:absolute;
}
#background {
border: solid 3px red;
z-index:1;
width: 20em;
height: 20em;
}
#foreground, #foreground2 {
border: solid 2px yellow;
z-index:2;
top: 15em;
height: 5em;
}
#foreground2 {
top: 22em;
}
</style>
<script type='text/javascript'>
window.onload=function(){
document.getElementById("foreground").contentDocument.write("<input type='text' value='text'/><input type='text'/>");
document.getElementById("foreground2").contentDocument.write("<input type='text' value='text'/><input type='text'/>");
document.getElementById("background").addEventListener("touchstart", function() {
console.log("touch");
});
}
</script>
</head>
<body>
<iframe id=background></iframe>
<iframe id=foreground></iframe>
<iframe id=foreground2></iframe>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)