开发者

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

开发者 https://www.devze.com 2023-03-21 21:46 出处:网络
Good day to all. I have this structure <html> <iframe> <div id=\"idd\">Some Content</div>

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

精彩评论

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