PDA

View Full Version : iframe accessing variables



gloosemo
08-29-2011, 04:46 PM
Hey

is it possible to access javascript variables in an iframe src page from the parent page, or vice versa. How do you do this? What about the DOM?

thanks

DaveyErwin
08-29-2011, 05:52 PM
<head>
<title>
Pi Calculator
</title>
<script language="JavaScript">
function getVarFromIframe(){alert(window.frames['ifrm'].a)}

</script>
</head>
<body>
<input type="button" onclick="getVarFromIframe()" />

<iframe name="ifrm" src="test.htm" />
</body>

test.htm....


<html>
<head>
<script>
var a = "hi from iframe";
</script>
</head
<body>
Hiya
</body>
</html>