让Octopress在新标签页中打开外链
今天发现Octopress一个小小的问题,就是无法将外链在新窗口中打开。于是就自己写了一小段javascript代码轻易的解决了这个问题。
代码如下:
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
function addBlankTargetForLinks () { | |
$('a[href^="http"]').each(function(){ | |
$(this).attr('target', '_blank'); | |
}); | |
} | |
$(document).bind('DOMNodeInserted', function(event) { | |
addBlankTargetForLinks(); | |
}); |
用法很简单:
- 将上面的代码下载下来或者复制其内容;
- 保存到octopress目录的source/javascripts/子目录中;
- 修改source/_includes/custom/header.html,在下面插入如下代码即可:
1 |
|