mviamari
mviamari

Reputation: 47

Pre-loaded iFrame Content

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

Answers (2)

rmhartog
rmhartog

Reputation: 2323

I know this question is old, but for future reference there is an attribute called srcdoc for iframes that allow you to provide the content directly.

https://www.w3schools.com/tags/att_iframe_srcdoc.asp

Upvotes: 2

Jared Farrish
Jared Farrish

Reputation: 49238

var stuff = "<div>I already know this is the iframe content I want.</div>";
document.getElementById('iframe').contentDocument.body.innerHTML = stuff;

http://jsfiddle.net/EcusH/

Upvotes: 1

Related Questions