0

I've searched this forum and found an answer which at least pointed me in the right direction, but I need a bit more help!

My problem: I want certain links to open in a new tab, but despite using target="_blank" the links open in the same page. The answer I found on these forums was that someone had an issue with their plugin, but I've checked mine and can't see that that's the case. What I HAVE found though, when using inspect element tool, is this:

//<![CDATA[
(function( $ ) { 'use strict';

    $('a').removeAttr('target');

    $('input,a,select,textarea,button').removeAttr('tabindex');

}(jQuery));
//]]>

Which looks like the key suspect to me! The only problem is, I don't know where in my website this is! I'm sorry if that sounds like a basic issue, but I just can't locate it. If anyone can help I'd me most grateful. The site is www.bibliophone.com and when you inspect the homepage you can find the above code.

Thank you,

Paul

lurker
  • 56,987
  • 9
  • 69
  • 103
Paul
  • 1
  • 1
  • My apologies, the full section of code is this: //<![CDATA[ (function( $ ) { 'use strict'; $('a').removeAttr('target'); $('input,a,select,textarea,button').removeAttr('tabindex'); }(jQuery)); //]]> – Paul Nov 02 '17 at 13:59
  • 1
    Read the documentation on this site regarding formatting of code, etc. Also, you should at least include the computer language you're using in the tags. I've added it for you. Otherwise, others who search for jquery questions will not find yours. – lurker Nov 02 '17 at 14:02
  • Just specifying `target="_blank"` doesn't open a new tab. You might want to read this question about [opening a new tab from Javascript](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript). – lurker Nov 02 '17 at 14:08
  • You can use the Sources tab in your browser's development tools to try to find which file contains this logic. Or if you can pull the project down to your box an IDE that has file search for text could also help you find it. – Taplar Nov 02 '17 at 14:10
  • Hi Lurker, thank you for adding the language for me, I'll do that in future. I'll also read more on opening links in a new tab. I thought I was pretty up to speed but probably not! – Paul Nov 02 '17 at 15:44
  • Taplar, thank you! I used your method and located the code which was indeed in a plugin (could have sworn I'd exhausted those avenues!) A simple change to the settings in the plugin has solved the problem. – Paul Nov 02 '17 at 15:45

1 Answers1

0

Use attribute target="_blank" for <a></a> elements

For add dynamically use JQuery code:

$(document).ready(function(){
    $('a').each(function(){
        $(this).attr('target','_blank');
    });
});
mscdeveloper
  • 2,749
  • 1
  • 10
  • 17