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.
Example:
Expand|Select|Wrap|Line Numbers
- var mv =
- [
- ["1","Fórum"],
- ["11","Aberto","http://labadm.metodista.br/MP.exe/mp?si=49179&w=3&p1=1&p2=172"],
- ["12","Pessoal","http://labadm.metodista.br/MP.exe/mp?si=49179&w=3&p1=1&p2=173"],
- ["2","Consulta"],
- ["21","Enviar E-mail","mailto:monocomltd.1305@macpenn.com.br"],
- ["3","Caso"],
- ["4","Sair do experimento"]
- ];
I load the two js files in my html in the static way (the first with the functions and the second with the data):
[HTML]<head>
.
.
.
<script type="text/javascript" src="ms_js/mp_mm.js"></script>
<script type="text/javascript" src="ms_js/mp_mm_d.js"></script>
</head>
[/HTML]
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 http://www.javascriptkit.com/javatut...criptcss.shtml.
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>
[/HTML]
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.
Wagner