blog/content/zh-cn/archives/10.md

1.1 KiB
Raw Blame History

title slug date categories tags
让Typecho文章内的超链接在新窗口打开 10 2017-05-27T12:13:00.000Z
吐槽
珠海
测试

Markdown支持两种形式的链接语法行内式和参考式两种形式。 而我们打开所生产的超链接,默认是在本窗口打开的,为了有更好的阅读体验,我们往往希望在新窗口。 要想让Typecho的文章中链接加上“_blank”也有很多种方法比如通过jQuery在网页搜索标签为其添加新窗口属性。 下面这种方式是直接修改Typecho程序源码来实现 在\var\CommonMark\HtmlRenderer.php 搜索

case CommonMark_Element_InlineElement::TYPE_LINK:
$attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
if ($title = $inline->getAttribute('title')) {
    $attrs['title'] = $this->escape($title, true);
}

return $this->inTags('a', $attrs, $this->renderInlines($inline->getAttribute('label')));

在return前加上下面这段代码

$attrs['target'] = '_blank'; // 给链接增加_blank属性