Posted in

Iframe que se ajusta a la altura de su contenido

El siguiente plugin adapta el height del iframe a las dimensiones de su contenido.

$(document).ready(function(){
$('iframe').iFrameResize();
});

Descargar iframe-resizer-master
Más información

En el código de dentro del iframe hay que incluir el siguiente archivo js:

/*! iFrame Resizer (iframeSizer.contentWindow.min.js) - v2.2.3 - 2014-04-07
 *  Desc: Include this file in any page being loaded into an iframe
 *        to force the iframe to resize to the content size.
 *  Requires: iframeResizer.min.js on host page.
 *  Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
 *  License: MIT
 */

!function(){"use strict";function a(a,b){"addEventListener"in window?window.addEventListener(a,b,!1):"attachEvent"in window&&window.attachEvent("on"+a,b)}function b(a){return t+"["+v+"] "+a}function c(a){s&&"console"in window&&console.log(b(a))}function d(a){"console"in window&&console.warn(b(a))}function e(b){function e(){function e(){function a(a){return"true"===a?!0:!1}var c=b.data.substr(u).split(":");v=c[0],i=void 0!==c[1]?parseInt(c[1],g):i,l=void 0!==c[2]?a(c[2]):l,s=void 0!==c[3]?a(c[3]):s,q=void 0!==c[4]?parseInt(c[4],g):q,w=void 0!==c[5]?a(c[5]):w,f=void 0!==c[6]?a(c[6]):f,j=m("margin",c[7]),p=void 0!==c[8]?c[8].toLowerCase():p,h=c[9],k=c[10]}function m(a,b){return-1!==b.indexOf("-")&&(d("Negative CSS value ignored for "+a),b=""),b}function n(a,b){void 0!==b&&""!==b&&"null"!==b&&(document.body.style[a]=b,c("Body "+a+" set to "+b))}function r(){void 0===j&&(j=i+"px"),n("margin",j)}function t(){document.documentElement.style.height="auto",document.body.style.height="auto",c('HTML & body height set to "auto"')}function x(){a("resize",function(){B("resize","Window resized")})}function y(){a("click",function(){B("click","Window clicked")})}function z(){o!==p&&c("Height calculation method set to "+p+"Height")}function A(){!0===f?(x(),y(),F()):c("Auto Resize disabled")}c("Initialising iFrame"),e(),r(),n("background",h),n("padding",k),z(),t(),D(),A()}function B(a,b,d,e){function f(){function a(a){function b(a){var b=/^\d+(px)?$/i;if(b.test(a))return parseInt(a,g);var d=c.style.left,e=c.runtimeStyle.left;return c.runtimeStyle.left=c.currentStyle.left,c.style.left=a||0,a=c.style.pixelLeft,c.style.left=d,c.runtimeStyle.left=e,a}var c=document.body,d=0;return d=document.defaultView&&document.defaultView.getComputedStyle?document.defaultView.getComputedStyle(c,null)[a]:b(c.currentStyle[a]),parseInt(d,g)}return document.body.offsetHeight+a("marginTop")+a("marginBottom")}function h(){return document.documentElement.scrollHeight}function i(){return Math.max(document.documentElement.scrollWidth,document.body.scrollWidth)}function j(){c("Trigger event ("+b+") cancelled"),setTimeout(function(){r=a},z)}function k(){c("Trigger event: "+b),r=a}function n(){m=q,A=s,k(),C(m,A,a)}var o={offset:f,scroll:h},q=void 0!==d?d:o[p](),s=void 0!==e?e:i();r in{size:1,interval:1}&&"resize"===a?j():(m!==q||l&&A!==s)&&n()}function C(a,b,d,e,f){function g(){void 0===f?f=x:c("Message targetOrigin: "+f)}function h(){var g=v+":"+a+":"+b+":"+d+(void 0!==e?":"+e:"");c("Sending message to host page ("+g+")"),y.postMessage(t+g,f)}g(),h()}function D(){w&&(c("Enable public methods"),window.parentIFrame={close:function(){B("close","window.parentIFrame.close()",0,0)},getId:function(){return v},sendMessage:function(a,b){C(0,0,"message",a,b)},setTargetOrigin:function(a){c("Set targetOrigin: "+a),x=a},size:function(a,b){var c=""+(a?a:"")+(b?","+b:"");B("size","window.parentIFrame.size("+c+")",a,b)}})}function E(){0!==q&&(c("setInterval: "+q+"ms"),setInterval(function(){B("interval","setInterval: "+q)},Math.abs(q)))}function F(){function a(){var a=document.querySelector("body"),d={attributes:!0,attributeOldValue:!1,characterData:!0,characterDataOldValue:!1,childList:!0,subtree:!0},e=new b(function(a){B("mutationObserver","mutationObserver: "+a[0].target+" "+a[0].type)});c("Enable MutationObserver"),e.observe(a,d)}var b=window.MutationObserver||window.WebKitMutationObserver;b?0>q?E():a():(d("MutationObserver not supported in this browser!"),E())}function G(){return t===""+b.data.substr(0,u)}G()&&n&&(e(),B("init","Init message from host page"),n=!1)}var f=!0,g=10,h="",i=0,j="",k="",l=!1,m=1,n=!0,o="offset",p=o,q=32,r="",s=!1,t="[iFrameSizer]",u=t.length,v="",w=!1,x="*",y=window.parent,z=50,A=1;a("message",e)}();
//# sourceMappingURL=../src/iframeResizer.contentWindow.map

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *


The reCAPTCHA verification period has expired. Please reload the page.