View Full Version : Scrolling the content of iFrames

name _F1
06-27-2006, 02:53 PM
I want to manipulate an iFrame using Javascript. I cannot alter the source of the document within the iFrame, so all the code will have to be in the main document.

I would like the document within the iFrame to scroll to a specified position on load, and have 2 buttons in the main document that scroll the document within the iFrame up or down.

I have tried to use the scrollTo() and scrollBy() functions to achieve this, but when I try to test it, nothing happens. :(

Note: I don't want the iFrame's scrollbars visible.

Any suggestions? Is this even possible?


06-27-2006, 03:13 PM
is there the page loaded in iframe belong to the same domain as the parent page? Otherwise it is not possible, as cross-domain manipulation is forbidden by default, for obvious security reasons.

name _F1
06-27-2006, 03:17 PM
That explains why it wasn't working; it's not in the same domain. :(

Thanks for the help.

Is there any other way I could scroll the content without using scrollbars, or perhaps have a button to show/hide the scrollbars?

06-27-2006, 03:23 PM
You may use the scrolling HTML attribute for the iframe...
<iframe scrolling="no" ........

but, would that be wise? If the content is much higher, the user will not be able to see the whole content...

CSS woun't work for IE, I reckon.......

name _F1
06-27-2006, 03:28 PM
With either of those methods, is it possible to toggle the scrollbars on and off?

EDIT: The page that I wish to display in an iFrame contains content that does not need to be viewed, but it needs to be viewable (ads, I'm not allowed to block them out). I just want a way that makes it possible to see the ads, while being as compact as possible (scrollbars take up a lot of space, and they can be annoying, which is why I would prefer not to have them).

06-27-2006, 03:50 PM
In theory yes, using either style or setAttribute() methods. Unfortunately, IE does not follow these methods in case the page is from another domain.

name _F1
06-27-2006, 03:59 PM
So there's no way to show the content of the page whilst being able to view the ads without showing the scrollbars?

EDIT: Is it possible to just show the page scrolled to a certain position, without the user being able to scroll at all [and so not be able to view the ads]?

06-27-2006, 04:09 PM
Nope. As long as the page belongs to another domain, you can not use any javascript methods (scrollBy(), scrollTo()) as those methods are to be aplied on the document. Or you can not reach the document of a page from another domain.

06-27-2006, 04:18 PM
You could nest the IFRAME in say a DIV(overflow:auto;) and scroll the DIV

name _F1
06-28-2006, 01:38 AM
How would I do that?

Would I be able to do what I said in the first post by doing that?

name _F1
06-28-2006, 11:48 AM
Would I still set the iFrame within the DIV to the dimensions I want, or would that be done in the DIV?

I'm still a little lost as to how I would scroll the DIV, would I be able to have it without scrollbars etc. like I wanted in the first post? Please explain exactly what to do and what I could achieve.

Thanks. :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum