HTML5: How to enable an extra set of restrictions for the content in an iframe element?
Solution:
HTML Code:
<!DOCTYPE html><!-- Declaration specifying the document type -->
<html><!-- Opening tag for the root element of the HTML document -->
<head><!-- Opening tag for the document's header section -->
<meta charset="utf-8"><!-- Metadata tag specifying the character encoding of the document -->
<title>How to enable an extra set of restrictions for the content in an iframe element</title><!-- Title of the HTML document -->
</head><!-- Closing tag for the document's header section -->
<body><!-- Opening tag for the document's body section -->
<iframe src="https://www.w3resource.com/html-css-exercise/basic/solution/iframe-sandbox.html" sandbox><!-- Inline frame element displaying content from an external source with sandbox attribute enabled -->
</iframe><!-- Closing tag for the iframe element -->
</body><!-- Closing tag for the document's body section -->
</html><!-- Closing tag for the root element of the HTML document -->
Explanation:
- This HTML code demonstrates how to enable an extra set of restrictions for the content within an iframe element using the sandbox attribute.
- The <iframe> element is used to embed content from another HTML document or website. In this case, its src attribute specifies the URL of the external content.
- The sandbox attribute is added to the iframe element without a value, which enables a default set of restrictions for the content within the iframe.
- These restrictions include preventing scripts, forms, and other potentially harmful content from executing or affecting the parent document.
- The content within the iframe will be rendered in a restricted environment, providing an extra layer of security against potential security vulnerabilities.
Live Demo :
See the Pen iframe-sandbox-answer by w3resource (@w3resource) on CodePen.
See the solution in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics