Skip to content

Instantly share code, notes, and snippets.

@arischow
Last active March 22, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arischow/1ebb35d1fd0b4d6c42cf2526f106908e to your computer and use it in GitHub Desktop.
Save arischow/1ebb35d1fd0b4d6c42cf2526f106908e to your computer and use it in GitHub Desktop.
JavaScript
// Get all query string
var after_slash = window.location.search // "search?number=007&name=Aris&addr=PHP+is+the+best"
var urlParams = new URLSearchParams(window.location.search);
console.log(urlParams.get('number')); // "007";
console.log(urlParams.get('name')); // "Aris"
console.log(urlParams.get('addr')); // "PHP is the best";
console.log(urlParams.has('name')); // true
console.log(urlParams.append('language', 'zh_CN')); // "?number=007&name=Aris&addr=PHP+is+the+best&language=zh_CN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment