[英]On IE11, cannot type in input box after removing iframe with contenteditable=true on body while that iframe was in focus
我有一個iframe,其主體設置為contenteditable=true
。 當我從DOM中刪除該iframe時,我所有其他文本區域和輸入都無法響應用戶輸入。 這些對象仍然報告它們具有焦點,並且仍然聲稱正在接收onkeydown事件,但是這些元素的內容永遠不會由於這些事件而改變。
從DOM中刪除帶有<body contenteditable = true>的iframe之后,如何確保其他輸入字段仍然有效?
這是iframe: true
時Froala編輯器的結構。
要求:
理想情況下,在將iframe從設置瀏覽器狀態的DOM中刪除后,我會調用一些普通的javascript函數,以將輸入字段恢復為正常狀態。
可以在下面找到代碼以及指向密碼筆的便捷鏈接。
<head>
<meta charset="UTF-8">
<script>
function removeIframe() {
var parent = document.getElementById("parent");
var iframe = document.getElementById("iframe");
parent.removeChild(iframe);
}
function setContent() {
document.getElementById("iframe").contentWindow.document.write("<html><body contenteditable='true'>Step 1: type something here</body></html>");
}
</script>
</head>
<body>
<div id="parent" style="display:flex; flex-direction:column;">
<div> This is a test for <b>IE 11 only</b>.
</div>
<input id="input" placeholder="Step 3: Try to type something into this input, note that you cannot, that's the problem.">
<iframe id="iframe" onload="setContent()">
</iframe>
<button type="button" onclick="removeIframe()">Step 2: click this button to remove the iframe that you just typed into</button>
</div>
</body>
下面指向codepen的鏈接提供了該問題的簡單再現。
來自: 刪除iframe后,窗口事件丟失,這顯然不是IE問題,我發現window.focus()
解決了該問題。
function removeIframe() {
var parent = document.getElementById("parent");
var iframe = document.getElementById("iframe");
parent.removeChild(iframe);
window.focus(); //new code here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.