开发者

javascript - get the content of a div inside an iframe in a js in the main page

Good day to all.

I have this structure

  <html>

         <iframe>

                <div id="idd">Some Content</div>

         </iframe>       

         <script type="text/javascript">
                 function getIddContent()
                 {
                      //This is the part I ask about
                 }

                 var content = getIddContent()开发者_开发知识库;
         </script>
  </html>

I need to get the content of the div inside the content variable. Thank you for your time. If I use document.getElementById("idd").innerHTML it says that the div doesn't exist.


Use the following code

function getIddContent() {
    return window.frames[0].document.getElementById('idd').innerHTML;
}

But you probably have to include the iframe contents via the src attribute on the iframe.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜