Skip to content

Instantly share code, notes, and snippets.

@odiak
Forked from namusyaka/gist:1091385
Created July 19, 2011 09:01
Show Gist options
  • Save odiak/1091777 to your computer and use it in GitHub Desktop.
Save odiak/1091777 to your computer and use it in GitHub Desktop.
外部リンク自動検出のやつ source:rskull
(function () {
var regex = /^(https?:\/\/(?:[0-9a-z\-]\.?)+(?::\d+)?)(?:\/.*)?$/,
replace = "$1",
baseURL = location.href.replace(regex, replace),
links = document.links,
i, len, href;
for (i = 0, len = links.length; i < len; i ++) {
href = links[i].href;
if (regex.test(href) && href.replace(regex, replace) !== baseURL) {
links[i].target = "_blank";
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment