问题
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