How to get iframe content and extract into textarea using JavaScript in this exemple, we learn how get content from iframe tag and extract source code inside textarea <p><button id="btn">run iframe</button></p> <iframe id="iframe"></iframe> <script type="text/javascript"> document.getElementById("btn").addEventListener('click', function runcode(){ var editor="<marquee>hello friends </marquee>" var doc = document.getElementById('iframe').contentWindow.document; doc.open(); doc.write(editor); doc.close(); }); </script> <p><button id="btn2">get content</button></p> <textarea id="output" style="width:100%; height:200px"></textarea> <script> document.getElementById("btn2").addEventListener('click', function getcode(){ var doc1 = document.getElementById('iframe').contentWindow.document; var doc_content= doc1.getElementsByTagName("HTML")[0].innerHTML; document.getElementById("output").value=doc_content; }); </script> © Manajmnt code Share to : ☷✎ Comments
Comments
Post a Comment
message