Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohnishiakira/1102273 to your computer and use it in GitHub Desktop.
Save ohnishiakira/1102273 to your computer and use it in GitHub Desktop.
外部リンクを自動で新しいタブで開く
@ohnishiakira
Copy link
Author

querySelectorAllに指定するセレクタを変えた。単純に"a"を指定するだけだと、相対指定の内部リンクも含まれてしまうため。a要素のhref属性の値が"http"で始まり、かつlocation.hrefで始まらないように指定するセレクタを書いたつもり。

@ohnishiakira
Copy link
Author

とりあえずCtrl(or Cmd)押しながらクリックすると別タブでバックグラウンドで開きますが、JavaScriptからやる方法はちょっと分からないですねえ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment