read iframe content html Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of read iframe content html without wasting too much if your time.

The question is published on by Tutorial Guruji team.

In my page i am having an iframe, the source of the iframe is a url which is having a page of another server.

When the page is loading its fetching the output and display it in the iframe.

Now i want to copy the content of the iframe once it is loaded completely using the below code —

<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
    function getContent()
    {
        var frame = window.frames["iView"].document;
        alert(frame.getElementById('CMS').innerHTML);
    }
</script>
</head>
<body>
  <iframe src="http://www.example.com/abc.jsp" name="iView" style="width:600px;height:800px;border:dotted 1px red" frameborder="0" onload="getContent();"></iframe>
</body>
</html>

But its not working, i tried to use many ways using jquery also, but in jquery its running the jquery before loading the iframe content which will definitely not work. Kindly suggest.

Answer

The browser loads the page content from top to bottom, according to the order of your code.

Use jquery ready function to make a function available after the document is loaded. In that case, your code should look like this:

<html>
<head>
<title></title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">

    $(document).ready(function(){
        function getContent()
         {
            var frame = window.frames["iView"].document;
            alert(frame.getElementById('CMS').innerHTML);
         }

         getContent();
    });
</script>
</head>
<body>
  <iframe src="http://www.example.com/abc.jsp" name="iView" style="width:600px;height:800px;border:dotted 1px red" frameborder="0"></iframe>
</body>
</html>
We are here to answer your question about read iframe content html - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji