How to structure a JavaScript/HTML website for global variables?

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:
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!
why don't you use server side language like php?

以上就是How to structure a JavaScript/HTML website for global variables?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准