'How use <iframe> allow attribute?
According to MDN Web Docs the allow attribute:
Specifies a policy feature for the
<iframe>.
The allow attribute uses Feature Policy. Feature Policy is made to developer allow some features of a certain site, but i don't understood for what this is for and how it works.
<iframe width="560" height="560" src="https://example.com" allow="camera; microphone"></iframe>
Please can give me examples?
Solution 1:[1]
Yes, exactly the attribute allow "specifies a feature policy for the <iframe>", but I don't really found very information about it and the values. But,for example, I use this code:
allow="geolocation"
in
<iframe id="form-iframe" src="https://google.com" allow="geolocation" width="800" height="600"></iframe>
Because I need that the web page can use the geolocation.
Solution 2:[2]
<iframe width="560" height="315" src="https://www.youtube.com/embed/owsfdh4gxyc" frameborder="0" allowfullscreen></iframe>
Enables a set of extra restrictions on any content hosted by the iframe. The value of the sandbox attribute can be either the empty string (all the restrictions are applied), or a space-separated list of tokens that remove each respective restriction.
Possible Values and Their Descriptions
allow-top-navigation
Allows the nested browsing context to navigate (load) content to the top-level browsing context.
allow-same-origin
Allows the content to be treated as being from its normal origin. Without this token, the content is forced into a unique origin, thus preventing it from accessing other content from the same origin. Also, without the allow-same-origin token, scripts are prevented from reading from or writing to the document.cookie IDL attribute, and blocks access to localStorage and openDatabase().
allow-forms
Allows form submission (i.e. the nested browsing context can submit forms). allow-scripts -Allows script execution (but not popup windows).
allow-pointer-lock
Enables Pointer lock. Pointer lock provides input methods based on the movement of the mouse over time, not just the absolute position of the mouse cursor. Pointer lock is useful for applications that require significant mouse input to control movements, rotate objects, and change entries. It is particularly essential for highly visual applications, such as those that use first-person perspective, as well as 3D views and modeling. By default, sandboxed iframes block Pointer lock. This attribute allows you to enable Pointer lock on sandboxed iframes.
allow-popups
Allows popup windows.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | P. J. Alzab |
| Solution 2 | UnrealApex |
