iframe scrolling
Moderator: General Moderators
iframe scrolling
Is there a way to scroll to a specific position for an iframe of a separate domain with javascript? For example, could I move the scroll position to x:100, y:200 on an iframe that has the src attribute or "http://yahoo.com"?
Basically what I'm trying to do is clip any webpage to a specific position and dimension. Is there some way to do this?
I appreciate all help on this.
Basically what I'm trying to do is clip any webpage to a specific position and dimension. Is there some way to do this?
I appreciate all help on this.
Re: iframe scrolling
Yes this can be done by setting using the style attribute in the iframe for example something like below would set the position from the top border and the left border.
style="position:absolute;Left:15;Top:100">
Hope that helps
style="position:absolute;Left:15;Top:100">
Hope that helps
Re: iframe scrolling
He is asking about the scrolling position, not iframe position.
Google returned me this
Google returned me this
Re: iframe scrolling
I'm not a member of experts-exchange.com (Btw, good thing they put a "-" inbetween experts and exchange. LOL).kaszu wrote:He is asking about the scrolling position, not iframe position.
Google returned me this
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: iframe scrolling
I googled and found this which I tested and it works (Mozilla). It sets the body margin, so I assume that you could scroll both direction, animate, etc.
Code: Select all
<html>
<head>
</head>
<body>
<iframe id="iframe1" style="height: 200px; width: 200px;"></iframe>
<script type="text/javascript">
var t = window.document.getElementById("iframe1");
t.src= "mypage.html";
t.onload = function()
{
t.contentWindow.document.body.style.marginLeft = "-100px";
}
</script>
</body>
</html>(#10850)
Re: iframe scrolling
This would work only if the "mypage.html" part was mine. I'm trying to do this cross-domain, which means I can't access the document object of the iframe. If I could access the document object of the iframe, I think I would just use window.scrollTo(x,y).arborint wrote:I googled and found this which I tested and it works (Mozilla). It sets the body margin, so I assume that you could scroll both direction, animate, etc.Code: Select all
<html> <head> </head> <body> <iframe id="iframe1" style="height: 200px; width: 200px;"></iframe> <script type="text/javascript"> var t = window.document.getElementById("iframe1"); t.src= "mypage.html"; t.onload = function() { t.contentWindow.document.body.style.marginLeft = "-100px"; } </script> </body> </html>
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: iframe scrolling
What if you created a script on your site that would proxy the pages your want (e.g., mypage.php?url=http://somesite.com/somepage.html)
(#10850)
Re: iframe scrolling
I guess I could do that, but are there any security risks involved? And what about bandwidth issues?arborint wrote:What if you created a script on your site that would proxy the pages your want (e.g., mypage.php?url=http://somesite.com/somepage.html)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: iframe scrolling
If you always know what the remote pages will be then you can make it secure by not passing parameters and having "sitefoo.php" and "sitebar.php" or passing IDs for pages that you lookup to check if they exist like "site.php?id=foo"
(#10850)