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

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

The above code is not working properly. Please tell me how to fix it.

+4
source share
3 answers

To get scrollTop in crossbrowser mode, 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 just the following:

 return document.documentElement.scrollTop || document.body.scrollTop 
+3
source

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

+1
source

Well, I think that what you are looking for is easy to get if you use jQuery. So maybe worth a look?

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

0
source

Source: https://habr.com/ru/post/1302589/


All Articles