如何强制外部 link 在 Tumblr 主题的同一选项卡上打开?

How to force an external link to open on the same tab in a Tumblr theme?

由于自动滚动的问题,我不得不更换我在 Tumblr 上的博客主题。在这个新主题上,所有外部 link 都会在新选项卡上打开,即使在删除代码中的所有 target="_blank"> 之后也是如此。

当我在博客上尝试代码时,它会将 target="_blank"> 放回代码中。

例如,如果我像这样留下 link:

<a href="EXTERNAL-WEB-SITE-GOES-HERE">
                    <svg class="social-accounts-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     viewBox="0 0 242.8 242.8" enable-background="new 0 0 242.8 242.8" xml:space="preserve">
    <path fill="#AAAAAA" d="SVG-VECTOR-CODE-GOES-HERE"/>
</svg>
 </a>

在 Chrome 上使用 F12 检查博客上的代码时,结果如下:

<a href="EXTERNAL-WEB-SITE-GOES-HERE" target="_blank">
                    <svg class="social-accounts-icon" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 242.8 242.8" enable-background="new 0 0 242.8 242.8" xml:space="preserve">
    <path fill="#AAAAAA" d="SVG-VECTOR-CODE-GOES-HERE"></path>
</svg>
 </a>

我已经使用 Chrome 和 Firefox 测试了博客,我得到了相同的结果。

您可以查看此 pastebin 上的博客代码:https://pastebin.com/LpkPMugw

感谢阅读。

你可以使用 jQuery:

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function($){
    $('.site-content a').each(function(){
        if( $(this).attr('href') && 0 != $(this).attr('href').indexOf('#') ) {
            $(this).attr('target', '_self');
        }
    });
});
// ]]></script>

如果您将该代码添加到您的站点,它将更改 .site-content 容器内的所有链接,使其具有 target=_self