1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

IFRAME how to scrollTo position?

Discussion in 'Web Design & Development' started by liqourmaster, Jun 23, 2008.

Thread Status:
Not open for further replies.
Advertisement
  1. liqourmaster

    liqourmaster Thread Starter

    Joined:
    Jun 7, 2007
    Messages:
    22
    Hi. I am trying to get an inframe's scroll position with a scrollTo() script but it just scrolls my main window page to desired position.

    here is the code I've been playing around with so far that I got off the site techmusing:

    <CODE>
    <script>
    function loadorder() {
    document.getElementsByName("iframename").src="http://www.megavideo.com/?v=I6LLA0QL"
    window.scrollTo(35,100)
    }
    </script>

    <IFRAME onload=loadorder() name="iframename" vspace="0" hspace="0" allowtransparency="true" scrolling="yes" marginwidth="0" marginheight="0" frameborder="0" style="border:0px;" width="476" height="526" SRC="http://www.megavideo.com/?v=I6LLA0QL"></IFRAME>
    </CODE>


    However, I found out the author of the article was not trying to get a default scrollTo for the IFRAME but the main window itself. So my question is, how do I do the same but for the IFRAME?
    I've tried putting the script before closing the IFRAME but it seems scripts dont run in iframe. Basically I'm trying to get the default position of the Iframe to center in on videos, pictures, etc.
    I'm a newbie so go easy on me guys. Thank you.
     
  2. tomdkat

    tomdkat Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,141
    :) First, you should understand the script you're using so you can tweak it to function the way you want or need if you're wanting to use it in a different way than it was intended to be used. :)

    With that being stated, let's look at your JavaScript:

    Code:
    <script>
    function loadorder() {
    document.getElementsByName("iframename").src="http://www.megavideo.com/?v=I6LLA0QL"
    [b]window.scrollTo(35,100)[/b]
    }
    </script>
    
    The line in bold above instructs the window object to scroll to the specified location. Since you want to scroll the iframe, try doing somthing like this:
    Code:
    function loadorder() {
    theFrame = document.getElementsByName("iframename");
    if (theFrame <> null) {
       theFrame.src="http://www.megavideo.com/?v=I6LLA0QL";
       theFrame.contentWindow.scrollTo(35,100)
    }
    else {
    alert("could not get iframe element!");
    }
    }
    
    You can get more information about this here.

    Hope that helps! :)

    Peace...
     
  3. liqourmaster

    liqourmaster Thread Starter

    Joined:
    Jun 7, 2007
    Messages:
    22
    Hi. Thanks for the reply.
    I tried your piece of code it still didnt work. I looked through the page you referred me to, tried changing the urls around but that didnt work either then I saw at the end of their post:

    Also note that the contents of the iframe must be on the same domain.

    So does that mean I cant do it with image and video sites not hosted by myself?
     
  4. tomdkat

    tomdkat Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,141
    I managed to get the iframe loading in the manner you are wanting to be using getElementById() instead of getElementsByName(). After that, I wasn't able to get the frame to scroll as instructed. At least not in Maxthon 2.1.1 (IE6 engine), Firefox 3, or Opera 9.5, all on Windows XP. Believe it or not, the iframe DID scroll in Safari 3.1.2 and I loaded Yahoo.com as the source of the iframe. Why Safari scrolled and the others didn't, I don't know.

    So, you might be SOL on doing what you're wanting to do.

    Peace...
     
  5. liqourmaster

    liqourmaster Thread Starter

    Joined:
    Jun 7, 2007
    Messages:
    22
    alright. thanks tom. do you know any other sites specializing in html? I use this site for all my tech needs :) I'll try asking around other sites and I'll keep you posted. You're probably right though I'm probably SOL.
    thanks for your help.
     
  6. tomdkat

    tomdkat Trusted Advisor

    Joined:
    May 6, 2006
    Messages:
    7,141
    If you do a search on "iframe scrollTo", you'll find plenty of other forums where they discuss HTML.

    Alternatively, I've had good success on the Opera forum in the "cross-browser web design with Opera" forum and I've had good success on the MozillaZine forum in the "web standards / evangelism" forum.

    Good luck!

    Peace...
     
  7. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/723806