Table of contents
- The iframe is often used to insert content from another source, such as an advertisement, into a Web page.
- An iframe can be used as the target frame for a link.
- The iframe element has an onload attribute, which can be used to trigger a script when an iframe has finished loading.
- The srcdoc attribute specifies the HTML content of the page to show in the iframe.
- Access elements of parent window from iframe
- Iframe sandbox
The is a feature of HTML that lets you embed content from another source in your Web page. The element has two attributes: src and srcdoc. The src attribute specifies the URL of the content to show, while the srcdoc attribute specifies an HTML string containing the contents to show. You can use an as a target frame for links, or use it as part of a data-binding process (see "More Examples" below).
The iframe is often used to insert content from another source, such as an advertisement, into a Web page.
The is often used to insert content from another source, such as an advertisement, into a Web page.
The tag can be used to embed objects, such as audio and video files, into a web page. It is also frequently used to embed ads or other content from other sites.
An iframe can be used as the target frame for a link.
can be used as the target frame for a link. This means that, when you click on a link within a page that contains an , the browser loads and displays content from another source (such as an advertisement) in.
The only thing you need to know about this is that it's not very common and is usually only used by developers.
The iframe element has an onload attribute, which can be used to trigger a script when an iframe has finished loading.
The onload attribute can be used to trigger a script when an has finished loading. This is useful if you’re loading data from another website, as it will allow you to check that the data was loaded successfully before continuing with your code.
The onload attribute can also be used to deal with cookies. If a domain sends a cookie named 'user_id', this will only be sent back to that domain if it's tapped in the URL bar after the page has finished loading (i.e., when you visit it). But what if you want your JavaScript code to set or update this cookie? You need something like:
document.getElementById('myForm').onsubmit = function() { var f = document; f.cookie("user_id", myFormInput[0].value); return false; }
The srcdoc attribute specifies the HTML content of the page to show in the iframe.
The srcdoc attribute specifies the HTML content of the page to show in the .
The element is used for embedding content from other websites into a web page. The srcdoc attribute can be used to specify any valid HTML markup that you want to be displayed in an iframe, even if it isn't related to the website shown in its parent document.
Access elements of parent window from iframe
You can access the parent window from iframe using
window.parent.document
property to get the parent window’s document.
Iframe sandbox
The sandbox attribute enables an extra set of restrictions for the content in the iframe. By default, no restriction is applied.
When the sandbox attribute is present, and it will:
treat the content as being from a unique origin
block form submission
block script execution
disable APIs
prevent links from targeting other browsing contexts
prevent content from using plugins (through ,