views:

526

answers:

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

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

A: 

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.

Andy E
A: 

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)

Olsson
Do you have an idea of what it takes to look into jQuery source code? It's simplier to look in YUI/prototype code then.
Marco Demajo
+1  A: 

To get scrollTop in a crossbrowser way jQuery does this:

fucntion 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
Marco Demajo