Created
April 15, 2014 20:27
-
-
Save prpatel/10769715 to your computer and use it in GitHub Desktop.
A simple JavaScript function for parsing URLScheme data. Intended for use in Appcelerator Titanium
This file contains 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
url = 'your.app.suffix://targetInYourApp?username=jesse&referer=some_partner'; | |
function parseURLSchemeData(url) { | |
var parsedData = {}; | |
url = url.substring(url.indexOf('//')+2); | |
if (url.indexOf('?') > 0 ) { | |
var viewTarget = url.substring(0, url.indexOf('?')); | |
parsedData['viewTarget'] = viewTarget; | |
url = url.substring(url.indexOf('?')+1); | |
var params = url.split('&'); | |
params.forEach(function(param) { | |
var pair = param.split('='); | |
parsedData[pair[0]] = decodeURI(pair[1]); | |
}); | |
} else { | |
var viewTarget = url; | |
parsedData['viewTarget'] = viewTarget; | |
} | |
return parsedData; | |
} | |
var schemeData = parseURLSchemeData(url); | |
console.log(schemeData); | |
console.log(schemeData['username']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment