Skip to content

Instantly share code, notes, and snippets.

@vaporic
Created July 17, 2015 17:25
Show Gist options
  • Save vaporic/db8d368d768d7d435072 to your computer and use it in GitHub Desktop.
Save vaporic/db8d368d768d7d435072 to your computer and use it in GitHub Desktop.
Obtener parámetros pasados por medio de JS
var scripts = document.getElementById('#IDENTIFICADOR DE <script>');
var queryString = scripts.src.replace(/^[^\?]+\??/,'');
var params = parseQuery( queryString );
function parseQuery ( query ) {
var Params = new Object ();
if ( ! query ) return Params; // return empty object
var Pairs = query.split(/[;&]/);
for ( var i = 0; i < Pairs.length; i++ ) {
var KeyVal = Pairs[i].split('=');
if ( ! KeyVal || KeyVal.length != 2 ) continue;
var key = unescape( KeyVal[0] );
var val = unescape( KeyVal[1] );
val = val.replace(/\+/g, ' ');
Params[key] = val;
}
return Params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment