我无法滚动工作,这是完整的内容: http://zed.mit.edu/scroll2/buc.php
我正在尝试刷新页面,同时保持内部 iframe 的滚动位置。
我想在主动滚动 iframe 时收到警报,这两个都失败了:
$(top).frames['#iframe_bucinid'].scroll(function() ....
$('#iframe_bucinid').scroll(function() ...
页面的 iframe 定义为:
<iframe class="inframe" src="bucin.php" name="bucin" id="iframe_bucinid">
请注意,获取scrollTop可以与
一起使用top.frames['bucin'].document.body.scrollTop
最佳答案
我使用以下代码成功(Chrome 和 Firefox)完成您所要求的操作:
$('#iframe_bucinid').contents().scroll(function() {
警报('你好');
});
你的代码和我的代码之间的主要区别是 contents()
部分。
不过,请务必彻底测试这一点,由于 same origin policy 的愚蠢实现,您可能会在某些浏览器中遇到问题。 .
关于javascript - iframe (firefox) 的 jQuery 滚动失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2774378/