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

kra*_*awl 5 html javascript tumblr tumblr-themes tumblr-html

Due to problems with autoscrolling, I had to replace my blog theme on Tumblr. On this new theme all external links open on a new tab, even after deleting all the target="_blank"> on the code.

When I try the code on the blog itself it puts the target="_blank"> back in the code.

If for example I leave a link like this:

<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>
Run Code Online (Sandbox Code Playgroud)

When inspecting the code on the blog using F12 on Chrome ends up like this:

<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>
Run Code Online (Sandbox Code Playgroud)

I already tested the blog using both Chrome and Firefox and I get the same result.

You can check the blog code on this pastebin: https://pastebin.com/LpkPMugw

Thanks for reading.

Mis*_*ime 3

你可以使用 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>
Run Code Online (Sandbox Code Playgroud)

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

  • 尝试将其放在末尾,例如页脚中。并确保网站上也加载了 jQuery。 (2认同)