Created
April 15, 2014 08:50
-
-
Save Cycymomo/10715000 to your computer and use it in GitHub Desktop.
urlParameterUpdate.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* remplace ou ajoute des paramètres à une URL */ | |
function urlParameterUpdate(id, value){ | |
if (value == '' || id == '') return; | |
// Vérifie si l'url contient "id=" | |
var oRegExp = new RegExp('&'+id+'(=[^&]*)?|^'+id+'(=[^&]*)?&?','g'); | |
var oUrl = (window.location.href).toString(); | |
// l'URL contient déja l'id | |
if (oUrl.match(oRegExp)) { | |
oUrl = oUrl.replace(oRegExp, '&'+id+'='+value); | |
} else { | |
// sinon on ajoute | |
oUrl += '&' + id + '=' + value ; | |
} | |
window.location.replace(oUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment