I'm building a dynamic website that gives travel directions, but I'm new to JavaScript and I'm not sure of the best way to code it.
Currently, I'm loading different parts of the site (header, main, footer) by having separate HTML pages for each element, and then loading these pages into the main page. For example, on the main page I have:
<body onload="initialize()">
<div id="header"></div>
<div id="main"></div>
<div id="footer"></div>
</body>
And in the imported JavaScript script I have:
function initialize()
{
$('#header').load('header.html');
$('#main').load('main.html');
$('#footer').load('footer.html');
}
The issue is that I want all three of these imported pages to have access to global variables and functions in a single JavaScript file where I will be storing route information, coordinates, etc. Specifically, I ran into problems where I was unable to call a function in my main JS script from the header.html page that had been loaded into the parent page.
What is the best way to do this? Any help is much appreciated!