Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts

    Scrolling the content of iFrames

    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?

    Thanks.
    Last edited by name _F1; 06-27-2006 at 01:57 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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?

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.......
    Last edited by Kor; 06-27-2006 at 02:51 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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).
    Last edited by name _F1; 06-27-2006 at 02:46 PM.

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    In theory yes, using either style or setAttribute() methods. Unfortunately, IE does not follow these methods in case the page is from another domain.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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]?
    Last edited by name _F1; 06-27-2006 at 03:04 PM.

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    You could nest the IFRAME in say a DIV(overflow:auto and scroll the DIV
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #10
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    How would I do that?

    Would I be able to do what I said in the first post by doing that?
    Last edited by name _F1; 06-28-2006 at 01:01 AM.

  • #11
    Regular Coder
    Join Date
    Jun 2006
    Posts
    225
    Thanks
    6
    Thanked 3 Times in 3 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •