-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiframe_inside_dom.html
51 lines (43 loc) · 1.25 KB
/
iframe_inside_dom.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shadow DOM with Multiple Iframes</title>
<style>
/* Style for the shadow host */
#shadow-host {
display: inline-block;
border: 1px solid #ccc;
padding: 10px;
}
/* Style for the iframes */
.iframe-container {
margin-bottom: 10px;
}
</style>
</head>
<body>
<!-- Shadow host element -->
<div id="shadow-host">
<!-- Shadow DOM container -->
<div id="shadow-container"></div>
</div>
<script>
// Get the shadow host and create a shadow DOM
const shadowHost = document.getElementById('shadow-host');
const shadowRoot = shadowHost.attachShadow({ mode: 'open' });
// Create and append multiple iframes to the shadow DOM container
for (let i = 1; i <= 3; i++) {
const iframeContainer = document.createElement('div');
iframeContainer.className = 'iframe-container';
const iframe = document.createElement('iframe');
iframe.src = `https://www.example.com`; // Set the iframe source URL
iframe.width = '400';
iframe.height = '300';
iframeContainer.appendChild(iframe);
shadowRoot.appendChild(iframeContainer);
}
</script>
</body>
</html>