[英]Using David Bradshaw's iFrameResize
我在寻求有关如何使用David Bradshaw的iframe调整大小的帮助? 我打算在Blogger上使用它,因为我正在使用iframe来显示跨域内容,因此我希望根据其内容的大小来调整iframe的大小。
这是我对Blog博客模板所做的操作,我已在</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 type="text/javascript" src="./system/iframeResizer.contentWindow.min.js"></script>
<script src="./system/jquery.js"></script>
但是什么也没发生,iframe不会自动调整大小:(有人可以帮我吗?
您需要在博客页面中切换脚本的顺序。 需要iframeResizer.min.js
来设置iframe,因此需要先设置iframe。
调用似乎也有错字。 它应该是:
$('iframe').iFrameResize({ /* options */ });
仅当页面上有jQuery时,此方法才有效。 如果没有,您应该可以像这样设置iframe:
iFrameResize({ /* options */ }, 'iframe');
其中iframe
是css选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.