<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>JavaScriptでGETパラメータを取得する</title>
</head>
<body>
<div>パラメータ</div>
<div id="app"></div>
<script>
// URLを取得
const url = new URL(window.location.href);
// URLSearchParamsオブジェクトを取得
const params = url.searchParams;
document.getElementById('app').textContent = params.get('q');
</script>
</body>
</html>