javascript - 使用 David Bradshaw 的 iFrameResize

标签 javascript jquery iframe

我正在寻求有关如何使用 David Bradshaw 的 iframe resizer 的帮助?我打算在博客上使用它,因为我使用 iframe 来显示跨域内容,我希望 iframe 根据其内容的大小调整大小。

这是我对博客模板所做的操作,我已在上面添加了此内容 </body>标签:

<script type='text/javascript'>
    $('iframe').iFrameSizer({
// Disable if using size method with custom dimensions.
autoResize                : true,

// Override the body background style in the iFrame.
bodyBackground            : null,

// Override the default body margin style in the iFrame.
// A string can be any valid value for the CSS margin attribute, 
// for example '8px 3em'. A number value is converted into px.
bodyMargin                : null,
bodyMarginV1              : 8,
bodyPadding               : null,

// When set to true, only allow incoming messages from the domain 
// listed in the src property of the iFrame tag. If your iFrame 
// navigates between different domains, ports or protocols; 
// then you will need to disable this option.
checkOrigin               : true,

// If enabled, a window.parentIFrame object is created in the iFrame 
// that contains methods outlined
enablePublicMethods       : false,

// 'bodyOffset' | 'body<a href="http://www.jqueryscript.net/tags.php?/Scroll/">Scroll</a>' | 'documentElementOffset' | 'documentElementScroll' | 
// 'max' | 'min' | 'grow' | 'lowestElement'
heightCalculationMethod   : 'offset',

// The default value is equal to two frame refreshes at 60Hz
interval                  : 32,

// Setting the log option to true will make the scripts in both the host page 
// and the iFrame output everything they do to the JavaScript console 
// so you can see the communication between the two scripts.
log                       : false,

// Set maximum height/width of iFrame.
maxHeight                 : Infinity,
maxWidth                  : Infinity,

// Set minimum height/width of iFrame.
minHeight                 : 0,
minWidth                  : 0,

// Enable scroll bars in iFrame.
scrolling                 : false,

// Resize iFrame to content height.
sizeHeight                : true,

// Resize iFrame to content width.
sizeWidth                 : false,

// Set the number of pixels the iFrame content size has to change by, 
// before triggering resize of the iFrame.
tolerance                 : 0,

// Called when iFrame is closed via parentIFrame.close() method.
closedCallback            : function(){},

// Initial setup callback function.
initCallback              : function(){},

// Receive message posted from iFrame with the parentIFrame.sendMessage() method.
messageCallback           : function(){},

// Function called after iFrame resized.
resizedCallback           : function(){},

// Called before the page is repositioned after a request from the iFrame
scrollCallback            : function(){return true;}
});
</script>
  <script src='http://javascript.ext/system/iframeResizer.min.js' type='text/javascript'/> 

我已将其添加到我的跨域页面的 </body> 上方标签:

<script src="./system/iframeResizer.contentWindow.min.js"></script>
<script src="./system/jquery.js"></script>

但是没有任何反应,iframe 没有自动调整大小:(有人可以帮助我吗?

最佳答案

您需要切换博客页面中脚本的顺序。设置 iframe 需要 iframeResizer.min.js,因此它需要放在第一位。

此外,调用中似乎存在拼写错误。应该是:

$('iframe').iFrameResize({ /* options */ });

只有当您的页面上有 jQuery 时,这才有效。如果您没有它,您应该能够像这样设置 iframe:

iFrameResize({ /* options */ }, 'iframe');

其中 iframe 是 css 选择器。

关于javascript - 使用 David Bradshaw 的 iFrameResize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35826209/

相关文章:

javascript - 正则表达式仅匹配带有表情符号且没有其他文本的文本

javascript - 在 javascript 中将 Canvas 保存为图像时颜色质量下降

javascript - PassportJS - 动态设置状态以允许在回调时重定向

javascript - 周期 2 : pager only displays link to first slide and hides the others

javascript - 广告横幅在浏览器 session 中只显示一次

iframe - 除非登录到 Google 帐户,否则嵌入式 Google 日历不会显示

jQuery scrollTop 在 iOS 上的 iframe 中不起作用

javascript - 单击复选框时jquery获取表单ID

javascript - React-router 和 iframe,浏览器历史记录

jquery - 选择下一个 UL?