You can get a link to the frame window object from the window.frames property. See https://developer.mozilla.org/en/DOM/window.frames
UPDATE:
You can access the global context of the named iframe using window[framename] . eg:
<iframe src="data.html" name="data"></iframe> <script> var myData = window.data.getData(); </script>
Although you need to make sure that the iframe is loaded.
In jQuery, you can use the content method if you want to access the iframe DOM:
$("iframe").contents()
All this assumes that the frame is located inside the same domain .
UPDATE [2]:
You asked if the getData function can be called from an external js file. The answer is yes (if I understand you correctly). Here is an example:
<html> <head> <meta charset="utf-8"> <title>parent page</title> </head> <body> <iframe src="data.html" name="data"></iframe> <script src="getdata.js"></script> </body> </html>
Then in the getdata.js file you have:
var dataFrame = window.data; // when the frame has loaded then call getData() dataFrame.onload = function () { var myData = dataFrame.getData(); // do something with myData.. }
Hope this answers your question :)
johnhunter
source share