0
1

More than 3 years have passed since last update.

若干、釣りタイトルのようになってしまったが、ここで述べることは、URLにGETパラメータ(隠しコマンド)を忍ばせ、それをJavaScriptで評価して処理を振り分けよう、という話である。

ただし、ここで述べる方法は Internet Explorer では動作しない。IE は完全終了に向けて動き始めているし、割り切り事項とした。

JavaScript
// 使用ブラウザ(ユーザーエージェント)を取得
var ua = window.navigator.userAgent.toLowerCase();

// Internet Explorer でないなら
if (ua.indexOf('msie') < 0 && ua.indexOf('trident') < 0) {

    // GETパラメータを取得
    var params = (new URL(document.location)).searchParams;
    var foo = params.get('foo');

    // パラメータ foo があれば
    if (foo != null) {
        // パラメータ foo を使った処理
        :
    }
}

使い方は以下の通り。

https://example.com/cgi-bin/bar.php?foo=ABCDE

もし貴方がサーバサイドプログラムに手を付けられない状況にあって、かつ、ちょっとしたデバッグ情報を関係者に表示させたいときに使えるかも。
まあ、隠しコマンドと言ってみたところで、ソースコードを見られてしまえば分かることではあるが。

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