-
The
iframeelement represents a nested browsing context
iframe element represents a nested browsing context
src
src attribute gives the address of a page that the nested
browsing context
is to contain
srcdoc
src attribute
srcdoc attribute, it will fall
back to the URL in the src attribute
name
target attribute of
aformbaseformtarget attribute of elements
windowName param in window.open()
name attribute, if present, must be a valid browsing context
name
value is used to name the nested browsing context.
value of this attribute;target=nametarget=id)
sandbox
sandbox attribute, when specified, enables a set of extra
restrictions on any content hosted by the iframe
value of the attribute can either be empty to apply all
restrictions,
or
space-separated tokens to lift particular
restrictions
allow-same-origin allow-top-navigation allow-formsallow-scriptsseamlesswidth
height
iframe stands for inline frame! (If you want to center, may need to use
display:block!)
<iframe width="425" height="350"
name="myIframe"
src="./origin_species_sample.html"
sandbox="allow-scripts">
</iframe>
<br>
<a href="https://tomgdow.com" target="myIframe">tomgdow</a>
<a href="https://ecss.tomgdow.com/" target="myIframe">ecss</a>
<a href="./alice_in_wonderland_sample.html" target="myIframe">Alice in Wonderland</a>
<a href="./origin_species_sample.html" target="myIframe">Origin Species</a>
anchor attribute target=myIframe
matches the iframe name
attribute (name="myIframe")
<iframe width="425" height="350"
name="myIframe2"
src="./alice_in_wonderland_sample.html"
sandbox>
</iframe>
<br>
<a href="https://tomgdow.com" target="myIframe2">tomgdow</a>
<a href="https://ecss.tomgdow.com/" target="myIframe2">ecss</a>
<a href="./alice_in_wonderland_sample.html" target="myIframe2">Alice</a>
<a href="./origin_species_sample.html" target="myIframe2">Origin Species</a>
ecss to see the sandbox difference.
<iframe width="425" height="350"
name="myIframe3"
src="./html/alice_in_wonderland_sample.html"
srcdoc="<div style=font-size:1.5em;>hello iWorld</div>">
</iframe>
window.addEventListener("load", function () {
document.querySelectorAll('iframe')[2]\
.contentDocument.body.style.color = '#FFFFFF';
document.querySelectorAll('iframe')[2]\
.contentDocument.body.style.backgroundColor = '#18836f';
});
srcdoc takes precedence over
src
<iframe
src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d19080.618943055015!2d-6.772560840429293!3d53.28814911621078!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x48677c2bcd0c6145%3A0xa00c7a997318440!2sCurryhills%2C%20Prosperous%2C%20Co.%20Kildare!5e0!3m2!1sen!2sie!4v1604437776571!5m2!1sen!2sie"
width="600" height="450"
frameborder="0"
style="border:0;"
allowfullscreen=""
aria-hidden="false"
tabindex="0">
</iframe>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/NMWzgy8FsKs?si=EaAfp0YpylewQ2DZ"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope;
picture-in-picture; web-share"
style="border:0;"
referrerpolicy="strict-origin-when-cross-origin"
allowfullscreen>
</iframe>