View Full Version : acess div that is outside of a iframe
jason21
08-10-2007, 06:19 PM
hi,
i have in main index a div called teste
<div id="teste"><b>over</b></div
and i want acess this div"change de content" from a iframe
if i want acess this div"change de content" in the same place i use this:
document.getElementById("teste").innerHTML=xpto
but how can i change inside a iframe?
thanks for your help
mcjwb
08-10-2007, 06:52 PM
You can access the div in the iframe through the window.frames collection, like this:
window.frames.myFrameName.document.getElementById("teste").innerHTML="xpto";
substituting myFrameName for the name of your iframe.
jason21
08-10-2007, 10:00 PM
hi,
thanks for your help its work fine :thumbsup:
now i have other question
i want open a link in iframe but when i open, the like they open inside of the iframe as normal, how can i open the link outside the iframe?
i dont want a new window i want use the same window that have the iframe
thanks :)
mcjwb
08-10-2007, 10:10 PM
The links in the iframe should have their target attribute set to "_top", e.g.
<a href="somePage.html" target="_top">link text</a>
jason21
08-11-2007, 12:36 PM
hi,
thanks for your help it works fine :thumbsup:
i have one more question :o
how can i resize a iframe in runtime the objective is after the content is loaded in a iframe the iframe ajust the size for donīt see the scroolbar is possibly
thanks for your help :)
Masterslave
08-11-2007, 12:53 PM
Add width and height to that iframe I guess:
iframe
{
width: 300px;
height: 300px;
overflow: auto;
}
jason21
08-11-2007, 01:11 PM
yes but with this the iframe dont ajust with the content as i want
i want a way to iframe auto ajust of the size of the current content.
the content necer have the same size and sometimes the scrollbars show because the iframe is too small and i want a way to ajust at least the size of height.
if a put width=100% this work fine but if i put height =100% this donīt work
this:
iframe
{
width: 300px;
height: 300px;
overflow: auto;
}
creat a fixed size
overflow: auto; what is for?
thanks :)
Masterslave
08-11-2007, 01:29 PM
I misunderstood your question, my bad.
Forget my code, I can't help you with that.
mcjwb
08-11-2007, 09:00 PM
hi,
thanks for your help it works fine :thumbsup:
i have one more question :o
how can i resize a iframe in runtime the objective is after the content is loaded in a iframe the iframe ajust the size for donīt see the scroolbar is possibly
thanks for your help :)
I had some problems with this one Jason! I thought I'd beable to use the normal methods (see quirksmode.org) to retieve the height of the iframe's document.body but for some reason it wouldn't work. It only returned the height of the iframe.
I found a work around though, put the code in the page that loads in the iframe! It's klugdey I know but hopefully someone can come up with a better way, maybe you should start a new thread about this?
Anyway here's what I came up with, put this in the page that loads in the iframe.
function resize(){
if(parent.frames.myFrame){// check the frame we want to resize exists.
frameRef = parent.document.getElementById("myFrame");//Need to grab it this way for some reason!
frameRef.width=document.body.scrollWidth+10; //add 10 to be on the safe side.
window.setTimeout("frameRef.height=document.body.scrollHeight+10",10);//need to put a delay in otherwise it tries to do it too fast and doesn't get the dimensions right!
}
}
and in the same page add onload="resize()" to the body element.
It does work, but I can't help but feel there must be a better way!
HWinMT
08-14-2007, 08:34 PM
if a put width=100% this work fine but if i put height =100% this donīt work
I struggled with this too. This worked for me:
html, body {
height: 100%;
margin: 0em 0em 0em 0em;
}
This reference was useful.
http://www.communitymx.com/content/article.cfm?cid=BAD95
I think there is a post on CodingForums about this too, but I can't find it now.
Jutlander
08-14-2007, 08:39 PM
html, body {
height: 100%;
margin: 0em 0em 0em 0em;
}
A general piece of advice. If you want the same value on all four sides of something just state it once:
margin: 0;
When something is zero, there's no need for a unit.
HWinMT
08-14-2007, 08:55 PM
When something is zero, there's no need for a unit
True. In my CSS I used margins to control the position/spacing of iFrames in DIVs. I zeroed them out for the post. Thanks for the tip.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.