Reputation: 47
I'm using an iframe in my page to display an embedded video.
The issue I have is that I already have the embed code I need, and can I render it directly into the iframe when I load the full page.
However, the iframe always seems to attempt to load a src attribute.
I'd like the iframe to keep the content I provide in it on render:
...
<div class="iframeWrapper">
<iframe>
<html>
<body>
<div>I already know this is the iframe content I want.</div>
</body>
</html>
</iframe>
</div>
...
The basic premise is that I'd prefer not to have to make a second request for the contents of the iframe, when I already know what the contents are supposed to be the first time through.
Is this even possible?
Thanks.
Edit: The iframe is purely for sandboxing. And not currently negotiable.
Upvotes: 1
Views: 2400
Reputation: 2323
I know this question is old, but for future reference there is an attribute called srcdoc
for iframe
s that allow you to provide the content directly.
https://www.w3schools.com/tags/att_iframe_srcdoc.asp
Upvotes: 2
Reputation: 49238
var stuff = "<div>I already know this is the iframe content I want.</div>";
document.getElementById('iframe').contentDocument.body.innerHTML = stuff;
Upvotes: 1