Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the body's content of an iframe in JavaScript?


To get the body’content, you can get the src attribute or try the following code snippet −

<iframe id = "myId" name = " myId ">...</iframe>

<script>
   var myDoc;

   if (window.frames && window.frames. myId && (myDoc = window.frames. myId.document)) {
     var iframeBody = myDoc.body;
     var content = iframeBody.innerHTML;
   }
</script>