6
I have the file Geragriddados.js and in this file I created a global variable and a function.
nomeTela = "";
function redirecionaTela() {
//redireciona para tela que chamou a tela de Dados.
location.href = nomeTela + ".html";
};
I would like to call this variable nomeTela in another JS document Geragraficoacucar.js and feed it with a value. And when I call the function redirecting() of Geragriddados.js in another HTML screen that this value is still fed.
Arquivo Geragraficoacucar.js:
function redirecionaTelaDados()
{
nomeTela = "acucar";
location.href = "dadosGrafico.html";
}
In the two HTML files of mine I have the link to the file . js, as below:
<script src="scripts/GeraGridDados.js"></script>
But this way I did, the global variable is empty when I call in the one that will use this nameTell.
Is this shape I’m making right? Is there a better way to do this?
Even though this is not your first question, welcome to Stackoverflow in Portuguese. I made an issue in your question removing thanks and greeting, given that our communication is not instant. I suggest you take a read on that topic in meta where this subject (greetings and thanks) has been dealt with. If there is anything else we can help, ask at the goal.
– emanuelsn
@emanuelsn thank you, I will follow this suggested pattern.
– Rafael Oliveira
Your question may contain 3 different answers, according to the point of view of understanding, we can state that:
"Você quer saber como utilizar uma variável global em mais de um arquivo js"
this is already a natural behavior of javascript, and also you want to"Utilizar uma variavel que não se perca ao redirecionar para outra página"
(only in this case the reply of @Antony Alkmim would be correct) But reading the contents of your question, you may not need to do this, (according to my reply), then please check what you really want before you mark.– Paulo Roberto Rosa
What I needed is what was suggested by Antony Alkmim and also by you Paulo Roberto. All the answers were helpful, thank you.
– Rafael Oliveira