简体   繁体   English

当滚动条出现在IFrame中时调用函数

[英]Calling a function when a scrollbar appears in an IFrame

I got an IFrame, in the onload event i set the height of the frame: 我有一个IFrame,在onload事件中,我设置了框架的高度:

function resizeFrame() { $("#iframeID").height($("#iframeID").contents().find("body").outerHeight(true)); }

Problem is: 问题是:
When the content of the frame is increasing without a postback (javascript or Async Postback with Ajax), a scrollbar appears. 当框架的内容增加而没有回发(javascript或带有Ajax的异步回发)时,将出现一个滚动条。
I found a solution for Firefox: 我找到了Firefox的解决方案:

document.getElementById("iframeID").contentWindow.addEventListener("overflow", resizeFrame, false);

But i can't find a solution for IE 7+8 但我找不到IE 7 + 8的解决方案
Anyone got an idea? 有人知道吗?

Probably you can fall back on the jQuery's resize() event handler, applied on the iframe's body. 可能您可以使用jQuery的resize()事件处理程序,该事件处理程序应用于iframe的主体。 It is meant to work with the window element only, but seems to work with any element on IE . 它仅适用于window元素,但似乎适用于IE上的任何元素

Sadly applying it to the iframe's body didn't work. 可悲的是,将其应用于iframe的身体没有用。
But i found a plugin where you can apply it to any element on the site: http://benalman.com/projects/jquery-resize-plugin/ 但是我找到了一个插件,您可以将其应用于网站上的任何元素: http : //benalman.com/projects/jquery-resize-plugin/

So that's my code(solution) now: 这就是我的代码(解决方案):

function initFrame() 
{      
  resizeAppFrame();

  if (navigator.userAgent.indexOf("MSIE") > 0)                          
    $(function() { $(appFrame.document.body).resize(resizeAppFrame) }) //IE
  else
    document.getElementById("applicationFrame").contentWindow.addEventListener("overflow", resizeAppFrame, false);  //FireFox
}
function resizeAppFrame()
{
  $("#iFrameID").height($("#iFrameID").contents().find("body").outerHeight(true));
}

... ...

<iframe name="appFrame" id="iFrameID" onload="initFrame();" frameborder="0" src="TestFrame.aspx" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM