Recuperer un paramètre de l'URL courante

Fermé
livemzone - 15 févr. 2010 à 11:51
avion-f16 Messages postés 19125 Date d'inscription dimanche 17 février 2008 Statut Contributeur Dernière intervention 23 mars 2023 - 15 févr. 2010 à 16:02
Bonjour,
avec java-script je veux Récupérer un paramètre de l'URL courante
par exemple :
mon url courante est
http://monsite.com/index.php?x=sssss+sss&y=rrrrrr+rrrrrrrr&k=ttttttttttttttttttttt

je veux récupérer la valeur x qui est [sssss+sss]
et l'afficher comme suis

le paramètre x contient comme valeur: sssss+sss

2 réponses

avion-f16 Messages postés 19125 Date d'inscription dimanche 17 février 2008 Statut Contributeur Dernière intervention 23 mars 2023 4 468
15 févr. 2010 à 16:02
1
PRO_PHP Messages postés 95 Date d'inscription jeudi 11 février 2010 Statut Membre Dernière intervention 27 avril 2010 1
15 févr. 2010 à 16:01
essais ca je suis pas sur....

function getVar (nomVariable)
{
var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&"
if (infos.indexOf("#")!=-1)
infos = infos.substring(0,infos.indexOf("#"))+"&"
var variable=0 {
nomVariable = nomVariable + "="
var taille = nomVariable.length
if (infos.indexOf(nomVariable)!=-1)
variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"))
}
return variable
}
0