How to get HTML content of an iFrame using JavaScript ? Last Updated : 15 Dec, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report The <iframe> tag specifies an inline frame. It allows us to load a separate HTML file into an existing document. Code snippet:function getIframeContent(frameId) { let frameObj = document.getElementById(frameId); let frameContent = frameObj. contentWindow.document.body.innerHTML; alert("frame content : " + frameContent);}Some of the definitions are given below: getIframeContent(frameId): It is used to get the object reference of an iframe.contentWindow: It is a property that returns the window object of the iframe.contentWindow.document: It returns the document object of the iframe window.contentWindow.document.body.innerHTML: It returns the HTML content of the iframe body.Example: The following example demonstrates to inclusion of separate HTML files into existing documents. html <!DOCTYPE html> <html> <head> <title> How to get HTML content of an iFrame using javascript? </title> </head> <body> <iframe id="frameID" src="ContentOfFrame.html"> </iframe> <a href="#" onclick="getIframeContent('frameID');"> Get the content of Iframe </a> <script> function getIframeContent(frameID) { let frameObj = document.getElementById(frameID); let frameContent = frameObj .contentWindow.document.body.innerHTML; alert("frame content : " + frameContent); } </script> </body> </html> ContentOfFrame.html: The following example demonstrates the HTML code content of file "ContentOfFrame.html". html <!DOCTYPE html> <html> <body> GeeksForGeeks: A Computer Science Portal For Geeks (It is loaded inside the iframe) </body> </html> Output: Output Comment More infoAdvertise with us Next Article How to change the width of an iframe to 100% using JavaScript ? R rumakr03 Follow Improve Article Tags : JavaScript HTML-Misc JavaScript-Misc Similar Reads How to Get the Content of an HTML Comment using JavaScript ? In this article, we will learn how to get the content of an HTML Comment Using Javascript. Comments are a best practice in programming and software development. In general, they can explain why a coding decision was made or what needs to be done to improve the code you're working on. HTML tags (incl 3 min read How to change the width of an iframe to 100% using JavaScript ? In this article, we are given an HTML document containing an <iframe> element and the task is to change the width of the <iframe> element to 100% with the help of JavaScript. There are two methods to change the width of the iframe which are discussed below: Method 1: This method uses the 2 min read HTML content modification using JavaScript JavaScript is the dynamic, lightweight, and most common computer programming language used to create web pages. It interacts with client-side and makes dynamic pages. JavaScript Can Change the Content of an HTML page. The getElementById() method is used to get the id of the element and change the HT 2 min read How to get/change the HTML with DOM element in JavaScript ? In order to get/access the HTML for a DOM element in JavaScript, the first step is to identify the element base on its id, name, or its tag name. Then, we can use inner.HTML or outer.HTML to get the HTML. Using the getElementById() method: This method gets/identifies the DOM elements using its ID an 3 min read Print the content of a div element using JavaScript If you want to print the content of a <div> element using JavaScript, you can achieve this by extracting the content and then opening a new window or popup to display and print it. This method involves capturing the content of the <div>, creating a new window, and using the print command 2 min read How to get the text without HTML element using JavaScript ? Given an HTML document containing some elements and the task is to get the text inside an HTML element using JavaScript. There are two methods to get the text without HTML element which are listed below: Using innerText propertyUsing textContent property Using innerText property: We can use innerTex 1 min read Like