Hello.. I'm a novice at Javascript/Jquery programming, so an apology if this is a simple/silly question.
I am trying to use the jQuery .getScript() function to refresh part of an existing webpage. This webpage must be run on a local file system, and a large amount of the formatting is done using frames.
Right now, there’s three main frames- a sidebar which displays possible “scopes” to choose from, a main frame which displays the majority of the contents of the webpage, and a footer frame. The main entry into the page is in an index.html file, which loads a sidebar.html, main.html, and footer.html file into each of the respective frames.
In turn, the main.html has a number of javascript files which it loads, the main being a main.js, which contains numerous functions to format/process the contents for this main window. After loading this javascript file, main.html loads a few javascript files, which contain the data which is going to be displayed in the main frame. These files that are loaded have a fixed data structure, and are dependent on the functions that were loaded by the main.js file.
Loading the webpage works fine now, but when a user tries to switch to another “scope”, the whole webpage is reloaded to make the switch. The only difference in the webpage is the content in the main.js frame, loaded in by a different set of .js files.
Enough text, let’s look at some code.
When the webpage loads, I tried to add a simple call to the getScript function in a .js file at the index.html level which handles switching scopes. This file, newFile, has different data definitions than the previously loaded oldFile.js which was loaded in the main.html file.
$.getScript(/js/newFile.js);
However this doesn’t work, since newFile.js depends on a parseData() function which is in main.js.
If I open firebug up, parseData is not located in the dom tab, which I assume is related to some scoping issue with the main.html and main.js file existing in a different frame.
I tried to do some targeting to the correct “frame” but I don’t think I understand jQuery enough to know what is happening.
$(window.parent.frames[0]).getScript(/js/newFile.js);
Any suggestions?
If I were to type into firebug console “parseData” it can not find it: “ReferenceError: parseData is not defined”
However, if I type in window.parent.frames[1].parseData, it can find the function.
Sorry about all the rambling and poor understanding of javascript. Hopefully someone can provide some assistance!
Thanks