forked from lawrencenull/HTML5-Sandbox-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
67 lines (62 loc) · 3.01 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script>
window.onload = function() {
if( "sandbox" in document.createElement("iframe") ) {
sandboxSupported = true;
var element = document.getElementById( "support" );
element.setAttribute( "style", "display: none;" );
} else {
var element = document.getElementById( "options" );
element.setAttribute( "style", "display: none;" );
}
var checkboxes = document.getElementsByTagName( "input" );
for( i = 0; i < checkboxes.length; i++ )
{
checkboxes[i].addEventListener("click", reloadSandboxedFrame );
}
reloadSandboxedFrame();
};
function reloadSandboxedFrame() {
if( !sandboxSupported ) { return; }
var checkboxes = document.getElementsByTagName( "input" );
var sandbox = "";
for( i = 0; i < checkboxes.length; i++ ) {
if( checkboxes[i].checked ) {
sandbox += checkboxes[i].value + " ";
}
}
var iframe = document.getElementById( "theFrame" );
if( !iframe ) {
iframe = document.createElement( "iframe" );
iframe.setAttribute( "id", "theFrame" );
iframe.setAttribute( "scrolling", "no" );
iframe.setAttribute( "width", "100%" );
iframe.setAttribute( "height", "600" );
document.getElementById("page").appendChild(iframe);
}
iframe.setAttribute( "sandbox", sandbox );
iframe.setAttribute( "src", "untrusted.html" );
}
</script>
</head>
<body id="page">
<h1>HTML5 IFrame Sandbox Demo</h1>
<article>
<h2 id="support">Your browser does not support the sandbox attribute!</h2>
</article>
<section id="options">
<h3>Options to modify the sandbox</h3>
<p>Checking an option will reload the page in the IFRAME below with the modified sandbox</p>
<input name="allowJavaScript" type="checkbox" value="allow-scripts" />Allow JavaScript<br/>
<input name="allowForms" type="checkbox" value="allow-forms" />Allow Forms<br/>
<input name="allowSameOrigin" type="checkbox" value="allow-same-origin" />Allow Same Origin<br/>
<input name="allowTopNavigation" type="checkbox" value="allow-top-navigation" />Allow Top Navigation<br/>
<input name="allowPopups" type="checkbox" value="ms-allow-popups" />Allow Popups (Just IE10)<br/>
<h3>Untrusted.html hosted in a sandboxed IFRAME</h3>
</section>
</body>
</html>