2013-03-08 152 views
0

如何獲得總的/最大的滾動高度和滾動頂部跨瀏覽器的iframe內容。iframe內容最大滾動高度和跨瀏覽器滾動頂部?

我試過波紋管代碼,這是返回scrollTop只在FireFox,但我想在瀏覽器中獲得scrollTop和總ScrollHeight。

<head> 
    <script src="../javascripts/jquery.min.js" type="text/javascript"></script> 
    <script type="text/javascript"> 
     function getIframeH(){ 
      var scrollHeight = $('#ifrm').contents().scrollTop(); 
      $('#dvMsg').html("scrollHeight :: " + scrollHeight); 
     } 
    </script> 
</head> 
<body> 
    <div id="dvMsg"></div> 
    <input id="Button1" type="button" value="button" onclick="getIframeH();" /> 
    <iframe id="ifrm" src="a.xml" ></iframe> 
</body> 
</html> 

感謝

+0

如果設置scrollHeight = $('#ifrm')。scrollTop()而不是.contents()。scrollTop()會發生什麼? – CodeMoose 2013-03-08 15:14:01

+0

scrollHeight = 0;現在甚至在FireFox中也是如此。 – pks 2013-03-11 04:55:23

+0

查看http://stackoverflow.com/questions/1852518/how-to-get-scrolltop-of-an-iframe – CodeMoose 2013-03-11 14:02:59

回答

0

基於this question - 基本上你需要檢查iframe的$("html").scrollTop(),然後$("body").scrollTop()如果html此爲0人都寫插件 - 不要推倒重來=)