Get the content of an iframe using JavaScript

From The IT Community
Jump to: navigation, search




How to get the content of an iframe with JavaScript:

  • First, define your iframe in the <body> part of your site:


<iframe src="http://www.theitcommunity.com/wiki/NewestPages?action=render" id="ifr" name="ifr" height="0" width="0"></iframe>
  • Then use this script to get the content of this iframe:
<script type="text/javascript">
function get_iframe(ifr_id) {
 var myIFrame = document.getElementById(ifr_id);
 var content = myIFrame.contentWindow.document.body.innerHTML;
}
</script>
  • You can use the variable content in every way you like :-)


Was this article helpful? Then please donate to keep The IT Community alive...

If you found this article helpful please share it, comment and help others by writing your own article.






Translate this page:




Articles found in the same category:
(max. 20 shown)