Access iframe functions

后端 未结 1 815
清歌不尽
清歌不尽 2021-01-21 03:29

This problem seem to happen only in chrome This is the iframe code




    

        
相关标签:
1条回答
  • 2021-01-21 04:09

    This works :

      <iframe id=iframetest src=iframetest.html></iframe>
      <script>
          $(window).load(function(){
             document.getElementById('iframetest').contentWindow.blahblah();
          });
      </script>
    

    Note that I used $(window).load to ensure the iframe was loaded. Using load on document wouldn't ensure the iframe is loaded.

    Of course, your iframe must have the same origin as the parent document (which also means you must open your file in http:// in your browser and not file://).

    EDIT : Working demo

    0 讨论(0)
提交回复
热议问题