I have the following scenario:
A parent file is calling a child iframe. the father and daughter are in completely separate folders.
I need the daughter to call a javascript function, also in javascript, which is in the parent. Because they are in separate folders, the parent.funcao();
code does not work, right? How do I replace this parent
with the server path where the parent is?
Example:
page.htm (Parent)
<style>
*{
margin:0;padding:0;
}
#iframe{
overflow:hidden;
}
</style>
<script>
function WHFRAME(w,h){
var FrameWH = document.getElementById("iframe");
FrameWH.style.width = w+"px";
FrameWH.style.height = h+"px";
}
</script>
<iframe src="iframe.htm" id="iframe"></iframe>
iframe.htm (daughter)
<html>
<head>
<title>pagina</title>
<style>
*{
margin:0;padding:0;
}
html,body{
overflow:hidden;
}
#corpo{
width:990px;
height:auto;
}
</style>
<script type="text/javascript">
function ResizeWH(){
var w;
var h;
w = document.getElementById("corpo").clientWidth;
h = document.getElementById("corpo").clientHeight;
window.parent.WHFRAME(w,h);
}
</script>
</head>
<body>
<div id="corpo">
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
<p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p> <p>Conteudo</p>
</div>
</body>
<script>
ResizeWH();
</script>
</html>
In the above example the two files are in the same folder, so it works, in my scenario the daughter is in another folder (same server, but in different units). Therefore, the <iframe src="iframe.htm" id="iframe"></iframe>
line would be <iframe src="http://caminho.../iframe.htm"id="iframe"></iframe>
.
Note: It is a script to leave the size of the dynamic daughter iframe within the parent.