2014-09-04 78 views
1

我有以下看法頁在asp.net MVC3,如何檢查iframe的HTML文件滾動到達底部或不使用jQuery

@using (Html.BeginForm()) 
{ 
<p> 
test test 
test test 
test test 
test test 
test test 
</p> 
<article border="0" > 
<iframe src ="@Url.Content("~/Content/test.html")" width="100%" height="300px" id="iframeContent"></iframe> 
</article> 
<p> 
test test 
test test 
test test 
test test 
test test 
</p> 
<table> 
<tr> 
<td> 
sample data 
</td> 
</tr> 
</table> 
} 

的IFRAME SRC的html文件是有點大,所以它是有滾動。我想檢查html文件滾動是否到達底部。如果達到最低點,我需要做一些驗證。

我可以通過使用下面的jquery完成整個頁面,但我無法弄清楚如何才能完成只有iframe滾動內容。任何建議人?

$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() == $(document).height()) { 
     alert("Bottom Reached!"); 
    } 
}); 

回答

-1

試試這個:

$('iframe').bind('load',function(){ 
    var $win=$('iframe').get(0).contentWindow; 
    $win.scroll(function() { 
     if($win.scrollTop() + $(window).height() == $(document).height()) { 
      alert("Bottom Reached!"); 
     } 
    }); 
}); 
+0

上面的代碼是不工作 – Govind 2014-09-05 08:08:49

+0

嘗試添加它來docuement ready事件。 mabe當你調用函數時iframe不在dom中 – MoLow 2014-09-05 11:22:23

+0

我試過的代碼是在dom準備好的只有.. – Govind 2014-09-06 21:46:32