I have a problem calling a JavaScript function in an iframe from the parent page. Here are my two pages:
mainPage.html
<html> <head> <title>MainPage</title> <script type="text/javascript"> function Reset() { if (document.all.resultFrame) alert("resultFrame found"); else alert("resultFrame NOT found"); if (typeof (document.all.resultFrame.Reset) == "function") document.all.resultFrame.Reset(); else alert("resultFrame.Reset NOT found"); } </script> </head> <body> MainPage<br> <input type="button" onclick="Reset()" value="Reset"><br><br> <iframe height="100" id="resultFrame" src="resultFrame.html"></iframe> </body> </html>
resultFrame.html
<html> <head> <title>ResultPage</title> <script type="text/javascript"> function Reset() { alert("reset (in resultframe)"); } </script> </head> <body> ResultPage </body> </html>
(I know document.all not recommended, but this page needs to be viewed only with IE, and I don't think the problem is)
When I click the Reset button, I get "resultFrame found" and "resultFrame.Reset NOT found". It seems to be referencing a frame, but cannot call a function in a frame, why?
javascript iframe
salle55 Oct 21 '09 at 12:30 2009-10-21 12:30
source share