Initially the iframe src is 3.html and it doesnt has the element which id is ‘p’, and I want to change the iframe src to 2.html and change the ‘p’ element value to 11. But it didn`t work. Could anyone give some solution?
What i want to do is simple in one event:
1)change the iframe src.
2)change the iframe’s element’s value.
1.html
<script type="text/javascript">
function testIframe()
{
test1();
test2();
}
function test1()
{
document.frames('myFrame').src='2.html';
}
function test2()
{
document.frames('myFrame').document.getElementById('p').innerHTML='11';
}
</script>
<body>
<input type="submit" id="button" onClick="testIframe()" value="ok">
<iframe name="myIFrame" id="myFrame" src="3.html">
</body>
2.html
<body>
<p id="p">33</p>
</body>
3.html
<body>
</body>
Hook up an ONLOAD event on the Iframe. You need to do this because you can only change the value AFTER the page has loaded. In the event handler, look at the SRC, if it’s the correct page, run your code.