当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - jQuery scroll fails for iframe (firefox)

问题描述:

I cannot get scroll to work, here is the complete stuff:

http://zed.mit.edu/scroll2/buc.php

I'm trying to refresh the page while maintaining the scroll position of the iframe inside.

I'd like to have an alert when I actively scroll the iframe, these two both fail:

$(top).frames['#iframe_bucinid'].scroll(function() ....

$('#iframe_bucinid').scroll(function() ...

The page's iframe is defined as:

<iframe class="inframe" src="bucin.php" name="bucin" id="iframe_bucinid">

Notice that getting the scrollTop works with

top.frames['bucin'].document.body.scrollTop

网友答案:

I had success (Chrome and Firefox) in doing what you're asking using the following code:

$('#iframe_bucinid').contents().scroll(function() { alert('hello'); });

The key difference between your code and mine being the contents() part.

Be sure to test this thoroughly though, you might run into problems in some browsers due to silly implementations of same origin policy.

分享给朋友:
您可能感兴趣的文章:
随机阅读: