How can I set the left and top of a document inside a frame


I have an iframe tag inside my document, in this frame I load another web page. I want that this page in my frame automatically scrolls to a certain position, so the user don't see the top of that page, just the important area.

Is this possible?

LVL 13
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

<body onload="document.getElementById("anc").click();">
This is the content that appears above the area you want the iFrame document to be positioned
<a name="spot"></a>
This is the content that you want them to see
<a href="#spot" id="anc"></a>

...might seem a little ugly, but avoids the browser detection that would be required with setting top and left.  The second anchor tag can really go anywhere inside the body, doesn't have to be at the end.


...of course this would have to appear inside the actual document that's contained within the iFrame, in other words, it's src.

If you're using this page in other areas, then you can add the anchors, and then set the iFrame's onLoad event procedure from the parent page within the onLoad of the parent

Let me know if ya have any questions.
just load the url with the hash code:  <iframe src="mypage.html#mysection">
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

> with the hash code
lol, nice lapsus... i meant the hash value
Duh, my brain's a bit like swiss cheese right now, thanks!
rettiseertAuthor Commented:

and thanks for your suggestions

I cant use  <iframe src="mypage.html#mysection"> 'cos mypage.htm is not mypage, its another page in another websithe and I have no control overt its source

and... can I access to the DOM of a document inside an iframe?
No, you cannot use javascript if the page is on a different domain, that's called cross-domain scripting.
Look at the page to see if it uses any "id".  All id's are anchors.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I'm not real sure about the copyright issues involved with using a page that doesn't belong to you embeded within your site?

I would suggest a link instead, and you should get permission from the company before linking your site to theirs, they might be okay with the iFrame usage? interesting question at any rate.  I would wager there probably is a way to access the DOM of another domain, I guess it just depends on weather you wanna be called a programmer, or a hacker.  ;)

Is this dynamic content that your displaying from someone elses site?  You could make your own page with the content you desire, though that's probly not any better for copyright concerns.  Personally I wouldn't be real comfortable having embedded content outside my control like that within one of my sites, if they change it or move it, you're SOL.


rettiseertAuthor Commented:
Hi, and thanks to all, well, yes, those sites are not mine, but I don't think its a copyright problem to have'em on my site.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.