Created
November 26, 2019 11:38
-
-
Save Farmatique/d9e77afd8e4d63c95ceb0197fe2d3d4a to your computer and use it in GitHub Desktop.
Get query strings from url
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
function getUrlParameter(name) { | |
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]'); | |
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); | |
var results = regex.exec(location.search); | |
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); | |
}; | |
// from url like sales/?search=roadmap+mcp+test | |
// using getUrlParameter('search') it return "roadmap mcp test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment