Created
March 3, 2016 20:16
-
-
Save leongaban/ccd00db5e034d8078893 to your computer and use it in GitHub Desktop.
Get variable from URL param
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
// For url with ?search=param | |
// http://stackoverflow.com/a/979997/168738 | |
function gurlp( name, url ) { | |
if (!url) url = location.href; | |
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | |
var regexS = "[\\?&]"+name+"=([^&#]*)"; | |
var regex = new RegExp( regexS ); | |
var results = regex.exec( url ); | |
return results == null ? null : results[1]; | |
} | |
var param = gurlp('search', window.location.href); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment