| Start | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Setting the Frame Size The IFrame can be resized using the |
||||||||||||||||||||||||||||||
| Sandboxing The following embeds an untrusted web page with all restrictions enabled To allow the page to run scripts and submit forms, add If there is untrusted content (such as user comments) on the same domain as the parent web page, an iframe can be used to disable scripts while still allowing the parent document to interact with it's content using JavaScript. The parent document can add event listeners and resize the IFrame to fit its contents. This, along with This sandbox is not a replacement for sanitizing input but can be used as part of a defense in depth (opens new window) strategy. Also be aware that this sandbox can be subverted by an attacker convincing a user to visit the iframe's source directly. The Content Security Policy (opens new window) HTTP header can be used to mitigate this attack. |
||||||||||||||||||||||||||||||
| Basics of an Inline Frame The term "IFrame" means Inline Frame. It can be used to include another page in your page. This will yield a small frame which shows the exact contents of the |
||||||||||||||||||||||||||||||
| Using the "srcdoc" Attribute The If the In the above example, if the browser does not support the |
||||||||||||||||||||||||||||||
| Using Anchors with IFrames Normally a change of webpage within an Iframe is initiated from with the Iframe, for example, clicking a link inside the Ifame. However, it is possible to change an IFrame's content from outside the IFrame. You can use an anchor tag whose Parameters
RemarksAn iframe is used to embed another document in the current HTML document. You CAN use iframes for displaying:
You SHOULD use an iframe as a last resort, as it has problems with bookmarking and navigation, and there are always better options other than an iframe. This SO question (opens new window) should help you understand more about the ups and downs of iframes. Same-origin policySome sites cannot be displayed using an iframe, because they enforce a policy called Same-origin policy (opens new window). This means that the site that the iframe lies on must be on the same domain as the one to be displayed. This policy also applies to manipulating content that lives inside of an iFrame. If the iFrame is accessing content from a different domain, you will not be able to access or manipulate the content inside of an iFrame. The iframe element on W3C (opens new window) |
| Value | Details |
|---|---|
allow-forms | Allows forms to be submitted. |
allow-pointer-lock | Enables the JavaScript pointer API. |
allow-popups | Popups can be created using window.open or <a target="_blank" |
allow-same-origin | The iframe document uses its real origin instead of being given a unique one. If used with allow-scripts the iframe document can remove all sandboxing if it's from the same origin as the parent document. |
allow-scripts | Enables scripts. The iframe document and parent document may be able to communicate with each other using the postMessage() API. If used with allow-same-origin the iframe document can remove all sandboxing if it's from the same origin as the parent document. |
allow-top-navigation | Allows the iframe's content to change the location of the top level document. |
Read Article
https://develop.horje.com/learn/1434/reference