开发者

capturing scroll event in a frame nested within an iFrame

开发者 https://www.devze.com 2023-03-27 16:30 出处:网络
I have an application that is reading the contents of an external doc into an iFrame and displaying it to the user. To make things more complicated, the content within my iFrame contains a frameset it

I have an application that is reading the contents of an external doc into an iFrame and displaying it to the user. To make things more complicated, the content within my iFrame contains a frameset itself, and our users want the height of the page to expand or contract with the height of the content. Basically, they don't want to see scroll bars. This works pretty well when I fire off the following JavaScript function on each page load within the frameset:

function resizeFrame() {
  var windowDoc = window.top.document
  var iframeCheck = null;
 // first, check to see if we can find a window.top.document
  if (windowDoc != null) {
    var iframeChec开发者_Python百科k = windowDoc.getElementById('docIframe');
  }
 // did we really find the iFrame?
  if (iframeCheck != null) {
   // clean out the iframe height to avoid appending every time
    iframeCheck.style.height = null;
    var scrollHeight = document.body.scrollHeight + 75;
    iframeCheck.style.height = scrollHeight + 'px'
  }
}

The page height is just right and everything looks good. The problem is, if the user puts their mouse inside the frame and tries to scroll with their mouse wheel, nothing happens. What I'd like to do is have to containing page move on a scroll event inside the frame. I think what I need to do is capture the scroll event and pass it to the containing page, but I can't quite figure this out. In fact, I put in a JavaScript alert in the onScroll() for the frame content and, scroll as I might, it never fires. It's almost as is the scroll event is completely inaccessible. Can anyone suggest a way to do this?

Thanks, Alex


I did find a way around this. I couldn't hook into the scroll event, but the mouse wheel event was still readily available and solved the problem nicely.

0

精彩评论

暂无评论...
验证码 换一张
取 消