I am working on how to call a function from an iframe and pass data to that function on the parent window. Both the iframe and the parent window are on the same domain. I have a navigation in the iframe that needs be tracked through SCORM and when the user clicks a link in the iframe it should call a function in the the main window and send the currentPage to the function. The links are in an array like this. I need it to call a function called goToPage() in the main window and pass the currentPage that is also on the main window in side the goToPage function. Can anyone help me with this problem? If you could show me in javascript that would be great. Thanks in advance.
function AddNav(links, linkURL) {
var links = new Array();
links[0] = "linkName1";
links[1] = "linkName2";
var linkURL = new Array();
linkURL[0] = "linkURL1.html";
linkURL[1] = "linkURL2.html";
document.write('<ul class="nav">');
for (i=0; i<links.length; i++) {
document.write('<li class="linkNum">'+links[i].link(linkURL[i])+'</li>');
}
document.write('</ul>');
getElementsByClassName("linkNum")[0].onclick = function () {
currentPage = 0;
var sendData = parent.currentPage;
});
getElementsByClassName("linkNum")[1].onclick = function () {
currentPage = 1;
var sendData = parent.currentPage;
});
}
function getElementsByClassName(linkNum) {
var elements = document.getElementsByTagName("*");
var found = [];
for(var i=0; i < elements.length; i++) {
if (elements[i].className == linkName) {
found.push(elements[i]);
}
}
return found;
}
Here’s a sample.
Parent
Frame: