iframe
Attributes -
- Global Attributes include
- Allow = Specifies a feature policy for the Feature policy= allows web developers to selectively enable, Disable, and modify the behavior of certain features andAPIs in the browser
- Referrerpolicy = Specifies which referrer information to send when fetching the iframe
Examples of feature policy -
- Change the default behavior of autoplay on mobile and third party videos
- Restrict a site from using sensitive devices like the camera, microphone, or speakers.
- Block the use of outdated APIs like synchronous XHRand document.write()
Iframe Allow Attribute = Use the allow attribute to specify a policy list for embedded content. this blocks the iframe from using the camera and microphone:
<iframe allow="camera 'none'; microphone 'none'">…</iframe>
Window Objects ->
it can be accessed by index numbers
- frameElement property - returns the frame where the window runs.
A frame can be any embedding element:<frame>, <iframe>, <embed>, <object>, etc. - window.length - property returns the number of (framed) windows in the window.
- frames property - returns an array with all window objects in the window
Its change the location of the first iframe element (index 0)
function myFunction() {
window.frames[0].location = "https://www.w3schools.com/jsref/";
}
HTML DOM IFrame Object
- Create an IFrame Object - by using the document.createElement() method
function myFunction() {
var x = document.createElement("IFRAME");
x.setAttribute("src", "https://www.w3schools.com");
document.body.appendChild(x); // appends a node (element) as the
last child of an element
}
- The sandbox attribute - enable security restrictions for iframes with untrusted content (such as scripts and forms).
IFrame object also supports the standard HTML DOM Elements and HTML DOM Events
Window.parent - property is a reference to the parent of the current window or subframe. window.top - returns a reference to the top-level window.