Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Web Design & Development Web Design & Development
Search Search
Search for:
Tech Support Guy > > >

IFRAME how to scrollTo position?


(!)

liqourmaster's Avatar
liqourmaster liqourmaster is offline
Computer Specs
Junior Member with 20 posts.
THREAD STARTER
 
Join Date: Jun 2007
Experience: Beginner/Intermediate
23-Jun-2008, 01:56 AM #1
IFRAME how to scrollTo position?
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.
tomdkat's Avatar
Computer Specs
Trusted Advisor with 7,141 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
23-Jun-2008, 01:07 PM #2
Quote:
Originally Posted by liqourmaster View Post
I'm a newbie so go easy on me guys. Thank you.
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"
window.scrollTo(35,100)
}
</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...
liqourmaster's Avatar
liqourmaster liqourmaster is offline
Computer Specs
Junior Member with 20 posts.
THREAD STARTER
 
Join Date: Jun 2007
Experience: Beginner/Intermediate
27-Jun-2008, 02:11 PM #3
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?
tomdkat's Avatar
Computer Specs
Trusted Advisor with 7,141 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
27-Jun-2008, 02:53 PM #4
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...
liqourmaster's Avatar
liqourmaster liqourmaster is offline
Computer Specs
Junior Member with 20 posts.
THREAD STARTER
 
Join Date: Jun 2007
Experience: Beginner/Intermediate
28-Jun-2008, 05:10 AM #5
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.
tomdkat's Avatar
Computer Specs
Trusted Advisor with 7,141 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
28-Jun-2008, 09:29 AM #6
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...
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
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.


(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑

Content Relevant URLs by vBSEO 3.3.2