Skip to content

Instantly share code, notes, and snippets.

@ricardoalcocer
Created January 4, 2013 19:16
Show Gist options
  • Save ricardoalcocer/4455128 to your computer and use it in GitHub Desktop.
Save ricardoalcocer/4455128 to your computer and use it in GitHub Desktop.
Receives a full URL and a query string parameter and returns its value. Modified from (http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) to work with Appcelerator Titanium. Example: var idValue=getParameterByName('http://somewebsite.com/page.php?id=12345','id'); idValue holds 12345
function getParameterByName(target,name){
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var results=target.match(regexS);
if(results == null){
return "";
}else{
return Ti.Network.decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment