By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Javascript Reload external Files

P: 2
I am very new using javascript and I faced a problem that with my expertise I cannot solve.
I wrote a small html file that handle a vertical menu. I wrote a function to show the menu correctly using javascript. The contents of the menu are dynamic changed. In my project I have two javascript file: the first has all the functions to handle the menu and the second has just a JSON array with the information for the menu.
Expand|Select|Wrap|Line Numbers
  1. var mv =
  2. [
  3. ["1","Fórum"],
  4. ["11","Aberto",""],
  5. ["12","Pessoal",""],
  6. ["2","Consulta"],
  7. ["21","Enviar E-mail",""],
  8. ["3","Caso"],
  9. ["4","Sair do experimento"]
  10. ];
(the language here is Portuguese)

I load the two js files in my html in the static way (the first with the functions and the second with the data):
<script type="text/javascript" src="ms_js/mp_mm.js"></script>
<script type="text/javascript" src="ms_js/mp_mm_d.js"></script>
I also run the menu function in the body section:
[HTML]<body onload="menu(mv,0),menu(mh,1)">[/HTML]

I wanted to change the menu information dynamically changing only the js data file as the user click in a link (this is a test project only), instead of running all page again, for this action I am using two function I could found here

The main function use parentNode.replaceChild to replace the mp_mm_d.js file (that has only a JSON var inside) when the user click the link:

[HTML]<a href="javascript:replacejscssfile('ms_js/mp_mm_d.js', 'ms_js/mp_mm_d1.js', 'js')">Troca Menu</a>
To run the menu function I include in the main function above a call to my menu constructor: menu(mv,0)

The mp_mm_d1.js is identical the older file mp_mm_d.js the the var mv contents (the name of the variable is the same but the contents).

Everything works fine, I mean: the mp_mm_d.js file was replaced by mp_mm_d1.js file and I got any error in the process, but the variable contents include in the mp_mm_d1.js was not loaded or not changed in the process.
I tried a lot of things to make this running well without success.
It seems that the browser do not reload the replaced file changing the variable as requested, or I am misunderstanding the whole process.
Is there a way to reload the js file in order to use the new variable information?

Thank you for reading this and hope to get an answer soon.

Nov 25 '07 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Have you inspected the DOM after replacing that it has indeed been replaced?
Nov 26 '07 #2

P: 2
Dear friends, I had already solved the problem! The key was to check the complete reload before continuing the process. Thanks all!
Nov 27 '07 #3

Expert Mod 15k+
P: 16,027
Glad you got it working. Post again if you have another question.
Nov 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.