源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

使用javascript实现Iframe自适应高度

  • 时间:2020-09-08 17:13 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:使用javascript实现Iframe自适应高度
方法一:
[u]复制代码[/u] 代码如下:
$(window.parent.document).find("#ContentIframe").load(function() {                     var main = $(window.parent.document).find("#ContentIframe");                     var thisheight = $(document).height();                     if (thisheight < 800)                         thisheight = 800;                     main.height(thisheight);                 });
这种写法,只能对于加载的时候对固有元素的自适应高度,当元素变化的时候(如添加了很多元素,高度变化后)不能及时改变父窗体的iframe高度。 方法二:
[u]复制代码[/u] 代码如下:
function setMainHeight() {     var main = $(window.parent.document).find("#ContentIframe");     var thisheight = $("body").height();     if (thisheight < 800) { thisheight = 800; }     main.height(thisheight+50);         setTimeout(setMainHeight, 2000); }
添加一个计时器,轮询判断子页面的高度变化。 以上2种都可以是iframe实现高度自适应,小伙伴们根据自己的项目需求,自由选择吧
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部