Forum Moderators: open

Message Too Old, No Replies

NEED HELP with IFRAME jumping to a section from an external webpage.

iframe code jump section onload external webpage

         

ineedtools

11:04 am on May 1, 2009 (gmt 0)

10+ Year Member



I want to load an external webpage through an iframe but when it's done loading the webpage, I want it to automatically jump to a particular section.

I know the code will go this way:

<iframe src="http://www.hiswebsite.com#section"></iframe>

However, in my case, I don't want to add the #section within the "src" tag. I just want to leave the url as it is.

Is there any way to make it jump without adding the "#section" at the end of the url?

tedster

1:05 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello ineedtools, welcome to the forums.

Here's a work-around you can try. First you create an extra url on your domain. This new url is a full page iframe that uses the video page as the iframe source. Your main page then uses your new extra url as the iframe src instead of the external site.

Because that new url is on your domain, you can now call the scrollTo method onload, and use it to move your new page to the exact pixel position you need.

I am curious - what's the problem with using a fragment identifier (#) in the iframe's src url?

ineedtools

1:19 pm on May 1, 2009 (gmt 0)

10+ Year Member



Can you provide the full code for the scrollTo & onload part.
Sorry, I'm still a complete newbie when it comes to programming webpages.

tedster

9:19 pm on May 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to work this out exactly for yourself to be sure it works in your situation - but I used all the right vocabulary so you can do the research easily. The main piece will be the opening body tag on the new url you create.

<body onload="window.scrollto(xposition,yposition)">

W3 Schools References: scrollTo() method [w3schools.com], onload event handler [w3schools.com]

You didn't answer the question, though - why avoid the fragement identifier at all, since there is already a nice section marked on the page you want to frame? I can't think of any downside and it's certainly a much easier and less problematic approach. There can be all kinds of trouble with pixel perfect positioning across different browsers.

ineedtools

6:30 am on May 2, 2009 (gmt 0)

10+ Year Member



Well I'm formulating a new method on earning at least $100 per day. This iFrame thingy got a huge part on it.

Thanks for the code.

I'll keep in touch if I have more questions.