Last active
August 29, 2015 14:20
-
-
Save lbj96347/4ba5a1704dd17c104245 to your computer and use it in GitHub Desktop.
javascript-get-url-parameter
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
function getParameter( 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]; | |
} | |
getParameter('q', 'hxxp://example.com/?q=abc'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment