/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Returns url param value * @author Arash Yalpani * * @param url The url to be queried * @param paramName The params name * @return paramName's value or false if param does not exist or is empty * * @example getUrlParam('http://localhost/?a=123', 'a') => 123 * @example getUrlParam('http://localhost/?a=123', 'b') => false * @example getUrlParam('http://localhost/?a=', 'a') => false */ getUrlParam: function(url, paramName) { var urlSplit = url.split('?'); if (!urlSplit[1]) { // no query return false; } var urlQuery = urlSplit[1]; var paramsSplit = urlSplit[1].split('&'); for (var i = 0; i < paramsSplit.length; i++) { paramSplit = paramsSplit[i].split('='); if (paramSplit[0] == paramName) { return paramSplit[1] ? paramSplit[1] : false; } } return false; }