現在開いてるページの URL を GET のパラメータに格納して外部サイトに移動するブックマークレットサンプル

現在の URL を特定のサイトに移動する際に GET のパラメータにエンコードして入れて、移動先でその URL で何か処理をさせる場合に使えそうなブックマークレットのサンプルです。

1
javascript:(function(){var url = location.href; var redirect_url = "http://example.com/?url=" + encodeURIComponent(url); document.location = redirect_url; })(

別タブや別ウィンドウで開く場合は下記のようにします。window.open(redirect_url,’_blank’) の所がミソです。

1
javascript:(function(){var url = location.href; var redirect_url = "http://example.com/?url=" + encodeURIComponent(url); window.open(redirect_url,'_blank'); })()

また URL 以外にも JS で取得できるものなら色々渡すことが可能です。

コメント

コメントは受け付けていません。