La url debe tener una estructura similar a http://pagina_de_ejemplo.com?variable1=valor1&variable2=valor2
Script inicial:
function getGET(){
var loc = document.location.href;
var getString = loc.split('?')[1];
var GET = getString.split('&');
var get = {};//this object will be filled with the key-value pairs and returned.
for(var i = 0, l = GET.length; i < l; i++){
var tmp = GET[i].split('=');
get[tmp[0]] = unescape(decodeURI(tmp[1]));
}
return get;
}
var get = getGET();
Cómo obtener los datos:
var variable1=get['variable1']; //se obtiene "valor1"
var variable2=get['variable2']; //se obtiene "valor2"
0 comentarios:
Publicar un comentario