0
I have the following scenario:
A parent file is calling an iframe daughter. the father and daughter are in completely separate folders.
I need the daughter to call in javascript a function, also in javascript, which is in the father. How are in different folders the code parent.funcao();
doesn’t work, right? How do I replace this parent
by the path of the server where the father is?
Example:
htm page (Father)
<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 drives). So the line <iframe src="iframe.htm" id="iframe"></iframe>
would be so <iframe src="http://caminho.../iframe.htm" id="iframe"></iframe>
.
Obs.: It is a script to leave the dynamical daughter iframe size inside the father.
Include your code as a verifiable example so that the problem can be reproduced.
– Leandro Angelo
No matter which folder you are in, iframe will always be the child. It just needs to be in the same domain.
– Sam
What if it is not in the same domain? How could it be done?
– Zacarias Junior
@Zacariasjunior if not in the same domain is not possible.
– Jorge.M