Javascript Reference - HTML DOM IFrame sandbox Property








The sandbox attribute from iframe element enables security restrictions for iframes with untrusted content such as scripts and forms.

The read-only sandbox property returns the value of the sandbox attribute in an iframe element.

If specified as an empty string (sandbox=""), the sandbox attribute enables a set of extra restrictions for the content in the iframe.

An empty string means all the restrictions is applied, while a space-separated list of pre-defined values that will turn off particular restrictions.

Browser Support

sandbox Yes 10 Yes Yes Yes




Syntax

var v = iframeObject.sandbox

Return Value

A String type value representing the value of the sandbox attribute.

Example

The following code shows how to get the value of the sandbox attribute.


<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="http://example.com" sandbox="allow-scripts"></iframe>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--  w w  w.j  a v  a 2  s . c o  m-->
    var x = document.getElementById("myFrame").sandbox;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows: