www.webdeveloper.com
Results 1 to 9 of 9

Thread: Auto set scroll position on Iframe...

  1. #1
    Join Date
    Aug 2009
    Posts
    6

    Auto set scroll position on Iframe...

    I am trying to set a scroll position on an iframe as soon as the page loads.

    I have:

    Code:
        
    <iframe src ="/frame.html" id="ab"></iframe>
    <script>
    	function scroll(){
    		window.getElementById('ab').scrollTo(5, 20);
    	}
    </script>
    Seems simple but its not working!

    Thanks for any advice.

  2. #2
    Join Date
    Aug 2009
    Posts
    6
    Correction:
    Code:
    <script>
    	window.getElementById('ab').scrollTo(5, 20);
    </script>

  3. #3
    Join Date
    Jun 2007
    Posts
    667
    Is the framed document on the same domain? If not then no chance.

    If it is and you control its content, you can put the scrollby in the framed document.

    Otherwise this should work.
    Code:
    document.getElementById('ab').onload = function(){ setTimeout("document.getElementById('ab').contentWindow.scrollTo(5, 20)", 1) }
    The timeout is for Opera, and the inability to use this is due to I.E.
    Y_U U_G_A_E_U_ B_S_A_D_

  4. #4
    Join Date
    Aug 2009
    Posts
    6
    Is the framed document on the same domain? If not then no chance.
    Why can I not scroll an IFrame if the URL is not on the same domain?

    Thanks for your suggestion, I have not tested it yet as the URL is on a different domain.

  5. #5
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    JavaScript has a same domain policy, you can not touch other domains. Protects your email, bank accounts, porn sites, etc.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  6. #6
    Join Date
    May 2003
    Location
    Between Baltimore and DC
    Posts
    3,579
    better solution if you have control of the other page is to use hash tags

    Code:
    src="foo.html/#scrollPoint1"
    and add a named anchor on the page
    Code:
    <a name="scrollPoint1" />
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint] | twitter | linkedin | http://www.pascarello.com

  7. #7
    Join Date
    Sep 2009
    Posts
    2

    So what is the conclusion?

    If I want to use an iframe to present a page from someone else's site, can I absolutely not set the scrollbar to any position other than far left?

  8. #8
    Join Date
    Aug 2009
    Posts
    6
    The way I done it, was to have a plain html page with an Iframe on it. Then use CSS and position the iframe so that it goes off to the left and top, leaving only the part of the page left you want.

    Then use another Iframe on your original page, and link the iframe to the above file.

    Does this make sense?

    Thanks for the info above A1ien51

  9. #9
    Join Date
    Sep 2009
    Posts
    2
    [QUOTE=acme_solutions;1033138]The way I done it, was to have a plain html page with an Iframe on it. Then use CSS and position the iframe so that it goes off to the left and top, leaving only the part of the page left you want.

    Then use another Iframe on your original page, and link the iframe to the above file.

    Does this make sense?

    [/QU.OTE]

    No, not to me. I don't know what you mean by "your original page", and in any case, the iframe is to appear in the middle of a page with other iframes.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles