Support » Plugin: Table of Contents Plus » New tab opened on click

  • davenoakes


    Hi there,

    I have a strange problem. When you click anything from the table of contents on my site, a new tab is opened, with the same URL then a forward slash and a hashtag reference (example #Northern_Laos_8211_Luang_Prabang).

    On the original tab nothing happens, unless I select “scroll down instead of jump down”, then the page open in the original tab does move to the correct place. (I have enabled this setting). On the new tab, the scroll top offset I have put in place is ignored. On the original tab, it is taken into account.

    Any idea what might be wrong here?

    Thanks in advance for your help!

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Juha Metsäkallas



    TOC uses what is termed “name” in html, see

    This is ok.

    I visited your site and found a TOC. As I suspected, the links in it are of form

    Chapter 1

    The “target” attribute tells to the webbrowser, that the page the link refers to should be opened into a new tab (Your browser can have a setting to open the page into a new window instead, but that’s rare.) So your WP installation has a setting somewhere, that tells to add that attribute to links. Go into the admin side and locate it.




    Thanks very much for your response. I’ve found that the issue is caused by the following snippet I have running, which opens external links in a new window. Would you have any idea how I could adapt it to disable the new tab function on the chapter form of target attribute? Or to somehow disable that snippet for TOC+ through other methods?

    function ready(fn) {
    if (document.readyState != ‘loading’) {
    } else if (document.addEventListener) {
    document.addEventListener(‘DOMContentLoaded’, fn);
    } else {
    document.attachEvent(‘onreadystatechange’, function() {
    if (document.readyState != ‘loading’)

    ready(function() {

    var website = window.location.hostname;

    var internalLinkRegex = new RegExp(‘^((((http:\\/\\/|https:\\/\\/)(www\\.)?)?’
    + website
    + ‘)|(localhost:\\d{4})|(\\/.*))(\\/.*)?$’, ”);

    var anchorEls = document.querySelectorAll(‘a’);
    var anchorElsLength = anchorEls.length;

    for (var i = 0; i < anchorElsLength; i++) {
    var anchorEl = anchorEls[i];
    var href = anchorEl.getAttribute(‘href’);

    if (!internalLinkRegex.test(href)) {
    anchorEl.setAttribute(‘target’, ‘_blank’);

    Juha Metsäkallas


    I have hard time to believe, that there would be a setting for opening internal links onto a new tab in a normal WP installation. Where did you get that code?

    Anyway the safest way to disable the new tab opening is to comment out the line
    anchorEl.setAttribute(‘target’, ‘_blank’);
    to form
    //anchorEl.setAttribute(‘target’, ‘_blank’);

    There are plenty of plugins, which make external links to open onto new tab, should you want to have such functionality.


    Thanks very much for your help. I have gone ahead and installed a plugin instead, the problem has gone away.

    By the way, I forgot to say thank you very much for such a great plugin! Very easy to use, looks good. Good work!

    Thanks again!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘New tab opened on click’ is closed to new replies.