Modify TAG Html inside an IFRAME with Javascript

Asked

Viewed 203 times

0

I would like to modify a tag that is within iframe on my page.

I think it will be clearer with the script below:

The "streamurl" tag is inside the iframe code.

<iframe id="player_externo" src="https://openload.co/embed/zFec7SV5aFU" width="605" height="400" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="true"></iframe>


<script type="text/javascript">
tempo = 5;
tempo = tempo*1000;
setTimeout(function(){
    var download = document.getElementById('streamurl').innerHTML;
	document.getElementById('player_externo').src = "https://openload.co/stream/" +download;
	alert(download);
}, tempo);
</script>

  • It’s the same domain?

  • No, I’m using this code on a blogger page.

1 answer

0

You can use the contentWindow or contentDocument.

var x = document.getElementById("player_externo");
var y = (x.contentWindow || x.contentDocument);
if (y.document)y = y.document;
var download = y.getElementById('streamurl').innerHTML;
x.src = "https://openload.co/stream/" +download;
alert(download);
  • You are not modifying your friend or giving ALERT.

  • Check the console if there is an error.

  • Uncaught Typeerror: Cannot read Property 'innerHTML' of null at index.html:8

  • The element exists?

Browser other questions tagged

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