How to open an html page from javascript, passing parameters

0

I am looking to open a new page, but when opening it, a parameter is passed. Example:

file A:

<html>
 .....
<script>
  var user="mi_nombre_de_usuario";
 location.href="/pagina_b"+user;

</scritp>
.....
 </html>

So far I have tried several things but I can not get it to open the "pagina_b" and also get a parameter. At the moment I have this code that I found on the internet.

function pasarVariables(pagina, nombres) {
pagina +="?";
nomVec = nombres.split(",");
for (i=0; i<nomVec.length; i++)
pagina += nomVec[i] + "=" + escape(eval(nomVec[i]))+"&";
pagina = pagina.substring(0,pagina.length-1);
location.href=pagina;
}
//location.href="../prueba?hola" ; 
pasarVariables("../prueba",username);
}

Any suggestion I would appreciate it.

    
asked by k1k4ss0 04.01.2019 в 23:53
source

2 answers

0

On line 2 of the second code try to put this:

pagina +="/?";

The url would look something like this:

pagina_b/?user=Name

Do not forget to put the sidebar

    
answered by 05.01.2019 в 14:56
-1

If what Ruben says does not work, try document.location="/ pagina? user = valor"

Or for a new window

Window.open ("/ pagina.html? user = value")

    
answered by 05.01.2019 в 15:11