• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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

Hello

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?

Thanks
0
rettiseert
Asked:
rettiseert
  • 4
  • 4
  • 2
2 Solutions
 
jessegivyDeveloperCommented:
<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.

Cheers,

Jesse
0
 
jessegivyDeveloperCommented:
...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.
0
 
GrandSchtroumpfCommented:
just load the url with the hash code:  <iframe src="mypage.html#mysection">
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

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?
0
 
GrandSchtroumpfCommented:
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.
0
 
jessegivyDeveloperCommented:
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?

...an 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.

Cheers,

Jesse
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now