inserthtml-in-text-adopted-to-other-document.html (1116B)
1 <!DOCTYPE html> 2 <html class="test-wait"> 3 <head> 4 <script> 5 function init1() 6 { 7 targetIframe = document.createElementNS('http://www.w3.org/1999/xhtml', 'iframe'); 8 targetIframe.srcdoc = "<html></html>"; 9 targetIframe.setAttribute("style", "width: 300px; height: 200px; border: 1px dotted green;"); 10 targetIframe.addEventListener("load", init2); 11 document.body.appendChild(targetIframe); 12 } 13 14 function init2() 15 { 16 targetWindow = targetIframe.contentWindow; 17 targetDocument = targetWindow.document; 18 19 var div = document.getElementById("div"); 20 textNode = div.firstChild; 21 22 targetDocument.body.appendChild(targetDocument.adoptNode(div, true)); 23 24 targetDocument.designMode = 'on'; 25 setTimeout(init3, 0); 26 } 27 28 function init3() 29 { 30 var rng = targetDocument.createRange(); 31 rng.setStart(textNode, 1); 32 rng.setEnd(textNode, 1); 33 targetWindow.getSelection().addRange(rng); 34 35 try { 36 targetDocument.execCommand("inserthtml", false, "<p>"); 37 } catch(e) {} 38 39 document.documentElement.removeAttribute("class"); 40 } 41 </script> 42 43 </head> 44 45 <body onload="init1();"> 46 47 <div id="div"> </div> 48 49 <script> 50 </script> 51 </body> 52 </html>