How to capture the value of the src attribute of an iframe?

Asked

Viewed 370 times

1

I have to capture the value of an iframe attribute in pagina.html, from the parent page pai.html. I’ve tried everything but failed.

pai.html:

<iframe id="meuframe" src="//www.site.com.br/fotos/pagina.html"></iframe>
<br></br>

<button onclick="iframejs();">icone</button>

<script>
    function iframejs() {
        var iframe = window.parent.meuframe.document.getElementById( "video_html" );
        alert( iframe.getAttribute( "src" ) );
    }
</script>

</body>
</html>

html page.

    <!DOCTYPE html>
    <html>
    ...

    <video id="video_html5" src="video.mp4" class="video-gs"></video> 

    ...
    </body>
    </html>
  • pai.html is with the iframe

2 answers

0


With jQuery, you can use the method meet:

$('#meuframe').contents().find('#video_html').attr('src');

0

ended up using this in javascript

    var video = window.parent.meuframe.document.getElementById("video_html").src; 

but does not work in Chrome ,

with jquery also did not work !

   $('#meuframe').contents().find('#video_html').attr('src');

but in IE I had no problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.