How to get iframe scroll position in IE using Java Script?

扶醉桌前 提交于 2019-12-22 08:04:13

问题


scrollPosition = window.frames[id].document.body.scrollTop;

The above code doesn't work correctly. Please tell me how to correct it.


回答1:


To get scrollTop in a crossbrowser way jQuery does this:

function GetScrollTop()
{
   var doc = document.documentElement
   var body = document.body;
   return ((doc && doc.scrollTop) || (body && body.scrollTop || 0)) - (doc.clientTop || 0);
}

I personally use simply this:

return document.documentElement.scrollTop || document.body.scrollTop



回答2:


If the frame's document is located on a different domain, you will not be able to access most properties and objects on it due to the same origin policy.




回答3:


Well, I think that what you're looking for is easy obtainable if you're using jQuery. So that might be worth looking into?

http://api.jquery.com/scrollLeft/ there is also scrollTop (api.jquery.com)



来源:https://stackoverflow.com/questions/2347491/how-to-get-iframe-scroll-position-in-ie-using-java-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!