Created
July 24, 2011 05:11
-
-
Save ohnishiakira/1102273 to your computer and use it in GitHub Desktop.
外部リンクを自動で新しいタブで開く
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @match *://*/* | |
// ==/UserScript== | |
(function (anchors) { | |
for (var i = 0, l = anchors.length; i < l; i++) { | |
anchors[i].target = "_blank"; | |
} | |
})(document.querySelectorAll("a[href^='http']:not([href^='" + location.href + "'])")); |
とりあえずCtrl(or Cmd)押しながらクリックすると別タブでバックグラウンドで開きますが、JavaScriptからやる方法はちょっと分からないですねえ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
querySelectorAllに指定するセレクタを変えた。単純に"a"を指定するだけだと、相対指定の内部リンクも含まれてしまうため。a要素のhref属性の値が"http"で始まり、かつlocation.hrefで始まらないように指定するセレクタを書いたつもり。