example.html - jscancer - Javascript crap (relatively small)
(HTM) git clone git://git.codemadness.org/jscancer
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
example.html (1192B)
---
1 <h1>Iframe</h1>
2
3 <p>
4 Embed an iframe and scale its width, height or both so there are less scrollbars.
5 Note that this requires serving from the same domain or adjusting the content security policies.
6 </p>
7
8 <iframe id="someid" class="autoresize-h" src="/" frameborder="0" border="0" width="960" height="100%"></iframe>
9
10 <script type="text/javascript">
11 // auto-resize iframes to fit its inner content: reduce scrollbars.
12 var iframes = document.getElementsByTagName("IFRAME");
13 for (var i = 0; i < iframes.length; i++) {
14 var iframe = iframes[i];
15 if (!iframe.classList.contains("autoresize-w") &&
16 !iframe.classList.contains("autoresize-h"))
17 continue;
18
19 // generate / bind element to function.
20 var fn = (function(el, rw, rh) {
21 return function(e) {
22 try {
23 var doc = this.contentWindow.document;
24 var width = doc.body.clientWidth || 0;
25 var height = doc.body.clientHeight || 0;
26 if (rw && width > 0)
27 el.width = width;
28 if (rh && height > 0)
29 el.height = height;
30 } catch(ex) {
31 }
32 };
33 })(iframe, iframe.classList.contains("autoresize-w"),
34 iframe.classList.contains("autoresize-h"));
35
36 iframe.addEventListener("load", fn, false);
37 }
38 </script>