How do I position the content of an I-frame when this content is non-editable (link to website) ?
Is there a way to shift the content position inside the iframe on initial load?
For example, my iframe is 200 x 200 px size. I want it to display content of a page that's 300px from the top and 100 px from the left.
There are some mistakes in your code. But, remember code below is working only when
<URL> domain and current page domain are same, otherwise browsers have denied access to body property of iframe document (for example IE 7 or Firefox 2).
You are right about the body property of the Iframe as it is giving an error (Access denied) if I use different domain.
But the main point is still I am not getting the inner frame content (-100px) left, as it was misleading, if we had some textbox on the page with focus in it then it is showing the textbox with cursor, and I thought it is working fine because the textbox
on the page is 200px from left, but if we use some other normal plain page and try to align left of -100px on the frame, then its not doing the right thing what we are looking for.
Yes, it just scrolls entire content of iframe. Also you can try to disable iframe scrollbars, but user always can scroll it even with disabled scrollbars.
koese
Member
359 Points
95 Posts
content position inside I-Frame
Nov 20, 2006 10:33 PM|LINK
How do I position the content of an I-frame when this content is non-editable (link to website) ?
Is there a way to shift the content position inside the iframe on initial load?
For example, my iframe is 200 x 200 px size. I want it to display content of a page that's 300px from the top and 100 px from the left.
Thanks
Rubo
Member
530 Points
101 Posts
Re: content position inside I-Frame
Nov 21, 2006 07:34 AM|LINK
Hi
You can do it by accessing iframe document object. For example, window["iframe_name"].document.body.marginLeft = "-50px";
koese
Member
359 Points
95 Posts
Re: content position inside I-Frame
Nov 21, 2006 11:11 AM|LINK
HI Rubo
I have tried your option but no luck am i going wrong some where
<html>
<body onload=window('frameA1').document.body.marginLeft = '-100px';>
<iframe name="frameA1" height="400" width="400" src="http://www.yahoo.com"></iframe>
</body>
</html>
Rubo
Member
530 Points
101 Posts
Re: content position inside I-Frame
Nov 21, 2006 01:34 PM|LINK
There are some mistakes in your code. But, remember code below is working only when <URL> domain and current page domain are same, otherwise browsers have denied access to body property of iframe document (for example IE 7 or Firefox 2).
<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= <URL>;
t.onload = function()
{
t.contentWindow.document.body.style.marginLeft = "-100px";
}
</script>
</body>
</html>
koese
Member
359 Points
95 Posts
Re: content position inside I-Frame
Nov 21, 2006 10:24 PM|LINK
Thanks for your effort
You are right about the body property of the Iframe as it is giving an error (Access denied) if I use different domain.
But the main point is still I am not getting the inner frame content (-100px) left, as it was misleading, if we had some textbox on the page with focus in it then it is showing the textbox with cursor, and I thought it is working fine because the textbox on the page is 200px from left, but if we use some other normal plain page and try to align left of -100px on the frame, then its not doing the right thing what we are looking for.
Hope you understood what I am trying to say.
koese
Member
359 Points
95 Posts
Re: content position inside I-Frame
Nov 23, 2006 02:31 AM|LINK
The solution is found at
http://willmaster.com/possibilities/archives/wmp20040713001.shtml
which is not moving or placing an Iframe, but moving the inside content of the IFrame
Rubo
Member
530 Points
101 Posts
Re: content position inside I-Frame
Nov 23, 2006 08:16 AM|LINK
Yes, it just scrolls entire content of iframe. Also you can try to disable iframe scrollbars, but user always can scroll it even with disabled scrollbars.