<html>
<body>
<script type="text/javascript">
/**
* Funcion que recoje los valores pasados por get de una url.
* Tiene que recibir el nombre de la variable a devolver su valor.
* Ejemplo: Si la url es del tipo:
* http://lawebdelprogramador.com/index.php?nombre=valor
* Podemos llamar a la funcion de esta manera:
* getURLParameter("nombre")
*/
function getURLParameter(name)
{ return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
document.write("Url: "+window.location.href); document.write("Protocol: "+window.location.protocol); document.write("Host: "+window.location.host); document.write("Path: "+window.location.pathname);
document.write("<hr>"); // Suponiendo que la url pase como parametro: ?valor1=casa&valor2=azul
document.write(getURLParameter("valor1")); document.write(""+getURLParameter("valor2"));
document.write("<hr>"); // Recorremos todos los paths de la url
// http://lawebdelprogramador.com/cursos/index.php?nombre=valor
// Devolvera cursos y index.php
pathArray=window.location.pathname.split('/'); for(i=0;i<pathArray.length;i++)
{ document.write(""+pathArray[i]); }
</script>
</body>
Comentarios sobre la versión: Versión 1 (0)
No hay comentarios