0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

javascriptでクエリストリングを取得する

Posted at

クエリストリングは以下のコードで取得できます

const queryString = window.location.search;
console.log(queryString);  // ?k=v&key=val&keyword=value

このままだと扱いづらいので、URLSearchParams を用いて変換します
ref: URLSearchParams|MDN
Can I use によるとIEはサポート外ですが、御時世、既に無視して良いでしょう

const queryString = window.location.search;
const queryParam = new URLSearchParams(queryString);
const kVal = queryParam.get('k');
console.log(kVal);   // v
const keyVal = queryParam.get('key');
console.log(keyVal);   // val
const keywordVal = queryParam.get('keyword');
console.log(keywordVal);   // value

?=& でごりごりしなくてヨシ!

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?