Skip to content

Instantly share code, notes, and snippets.

@seriwb
Last active December 16, 2017 07:30
Show Gist options
  • Select an option

  • Save seriwb/3617db79e9e0715d4b04 to your computer and use it in GitHub Desktop.

Select an option

Save seriwb/3617db79e9e0715d4b04 to your computer and use it in GitHub Desktop.
はてなブログのリンクを別ウインドウで開くようにするためのスクリプト。デザイン設定のヘッダに以下のHTMLを追加する。キーワードも別ウインドウで出したい場合は、11行目の条件を削除すること。
<script>
window.onload = function()
{
var entry_contents = document.getElementsByClassName("entry-content");
for (var i=0; i < entry_contents.length; i++) {
var links = entry_contents[i].getElementsByTagName("a");
for (var j=0; j < links.length; j++) {
if (!links[j].getAttribute('href').startsWith('#') || (
links[j].className !== "entry-see-more" &&
links[j].className !== "keyword")) {
links[j].setAttribute("target", "_blank");
}
}
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment