Parámetros entre páginas html

Hola, necesito recoger parámetros desde una página html para generar un link desde esa misma página utilizando una url que recibo como parámetro. Se que javascript me lo permite pero no se como hacerlo. Si tienes algo de código al respecto te agradecería que me lo comentases. Gracias de antemano.

1 Respuesta

Respuesta
1
Este es un ejemplo de una página HTML que te muestra los parámetros que recibe usando javascript. La línea que se le pasa se toma usando "this.location.href". Estudia bien el código:
<HTML>
<HEAD>
<TITLE>Utilise Query String In JavaScript</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
// Get the query string with javascript
// just like a cgi script would
// so send it my_page.html?food=eggs&drink=beer
// and you will have the variable query_food == eggs
// and the variable query_drink == beer
// everywhere in the document
// the whole variable _query_string == food=eggs&drink=beer
// is also available to you
// ***** Please leave this courtesy note in *****
// *
// * downloaded for free from http://www.summerholiday.org/freecode/
// *
// ***** Thank you *****
// BEGIN GET QUERY STRING CODE
queryVar = this.location.href;
var inq = queryVar.indexOf('?');
queryVar = queryVar.substring(inq + 1);
if (inq > 0)
{
_query_string = queryVar; // full query is also available to body
}
var text1 = "&";
var strLength = queryVar.length, txtLength = text1.length;
var i = queryVar.indexOf(text1);
while (i+txtLength < strLength)
{
if (i > 0)
{
qrysplit(queryVar.substring(0,i),"=");
}
else
{
qrysplit(queryVar,"=");
}
queryVar = queryVar.substring(i+txtLength,strLength);
var i = queryVar.indexOf(text1);
if (i < 1)
{
i = strLength + 1; // end while
}
}
qrysplit(queryVar,"="); // last one
function qrysplit(string,text)
{
name = string.substring(0,string.indexOf(text));
value = string.substring(string.indexOf(text) + 1);
eval("query_" + name + " = value;");
// comment the previous line and uncomment this next line if you want to
// use UNESCAPE, that is, turn %20 into a space, %22 into double quotes, etc.
// eval("query_" + name + " = unescape(value);");
}
// END GET QUERY STRING CODE
//--></SCRIPT>
</HEAD>
<BODY>
<P>
<SCRIPT LANGUAGE="JavaScript"><!--
var _query_string; // call before reference in case undefined
document.write("the query string is "" + _query_string + "". ");
var query_name; // call before reference in case undefined
document.write("the name is "" + query_name + "". ");
var query_name2; // call before reference in case undefined
document.write("the name2 is "" + query_name2 + "". ");
//--></SCRIPT>
</P>
</BODY>
</HTML>
Es

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas