add script to resize iframe - jscancer - Javascript crap (relatively small) | |
git clone git://git.codemadness.org/jscancer | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 9ba8da523384de2bdf895531b8145f93441ceec9 | |
parent ba476d77a16b011c02195bcd05570f4bc0886c47 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Mon, 30 Oct 2023 18:33:06 +0100 | |
add script to resize iframe | |
Diffstat: | |
A resizeframe/example.html | 38 +++++++++++++++++++++++++++++… | |
1 file changed, 38 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/resizeframe/example.html b/resizeframe/example.html | |
@@ -0,0 +1,38 @@ | |
+<h1>Iframe</h1> | |
+ | |
+<p> | |
+Embed an iframe and scale its width, height or both so there are less scrollba… | |
+Note that this requires serving from the same domain or adjusting the content … | |
+</p> | |
+ | |
+<iframe id="someid" class="autoresize-h" src="/" frameborder="0" border="0" wi… | |
+ | |
+<script type="text/javascript"> | |
+// auto-resize iframes to fit its inner content: reduce scrollbars. | |
+var iframes = document.getElementsByTagName("IFRAME"); | |
+for (var i = 0; i < iframes.length; i++) { | |
+ var iframe = iframes[i]; | |
+ if (!iframe.classList.contains("autoresize-w") && | |
+ !iframe.classList.contains("autoresize-h")) | |
+ continue; | |
+ | |
+ // generate / bind element to function. | |
+ var fn = (function(el, rw, rh) { | |
+ return function(e) { | |
+ try { | |
+ var doc = this.contentWindow.document; | |
+ var width = doc.body.clientWidth || 0; | |
+ var height = doc.body.clientHeight || 0; | |
+ if (rw && width > 0) | |
+ el.width = width; | |
+ if (rh && height > 0) | |
+ el.height = height; | |
+ } catch(ex) { | |
+ } | |
+ }; | |
+ })(iframe, iframe.classList.contains("autoresize-w"), | |
+ iframe.classList.contains("autoresize-h")); | |
+ | |
+ iframe.addEventListener("load", fn, false); | |
+} | |
+</script> |