Skip to content

Instantly share code, notes, and snippets.

@ogaty
Last active July 19, 2023 04:29
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 ogaty/fc97893de9d9ad9caecc47b5031e7453 to your computer and use it in GitHub Desktop.
Save ogaty/fc97893de9d9ad9caecc47b5031e7453 to your computer and use it in GitHub Desktop.
javascript urlクラス
var x = new URL(location.href);

//path 置換
x.pathname = '/aaa';

// hash置換
x.hash = 'user';

// query置換
x.search = 'aaa=bbb';

// query追加
x.searchParams.append('a', 'b');
var y = new URLSearchParams(location.search.substring(1));
y.get('aaa');
var z = new URLSearchParams([['a', 1], ['b', 2]]);
x.search = z;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment