Open link in new tab without using HTML target="_ blank"

1

Scenery

I'm optimizing a page where about 200 partner images are displayed (very small does not require paging), these images are wrapped in a <a> tag, and all partner sites open in new tab ( target="_blank" ).

Obs: I saw related materials on the site but the Javascript used to answer the question (which were not so similar to this one) was too great which would take away all the savings obtained and would need adaptations to the problem .

Question

How can I suppress target="_blank" and still keep the page opening in a new tab

HTML Code

<div id="minor_partners" class="col-md-10 col-md-offset-1">
    <a href="" target="_blank"><img class="link_thumb" src="" title=""></a>
</div>
    
asked by anonymous 21.07.2015 / 17:03

1 answer

2

The way I found it was to use a library function jQuery .click() so that when the image was clicked the value _blank was assigned to the target property.

HTML code for testing

<html>
    <head>
    <title>
        Abrindo em nova Aba
    </title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script></head><body><divid="minor_partners" class="col-md-10 col-md-offset-1">
        <a href="http://pt.stackoverflow.com/"><img class="link_thumb" src="https://clubdopenguinnotice.files.wordpress.com/2010/08/edit-icon.jpg"></a><ahref="http://pt.stackoverflow.com/"><img class="link_thumb" src="https://clubdopenguinnotice.files.wordpress.com/2010/08/edit-icon.jpg"></a><ahref="http://pt.stackoverflow.com/"><img class="link_thumb" src="https://clubdopenguinnotice.files.wordpress.com/2010/08/edit-icon.jpg"></a></div><ahref="http://pt.stackoverflow.com/"><img class="link_thumb" src="https://clubdopenguinnotice.files.wordpress.com/2010/08/edit-icon.jpg"></a>
    </body>
</html>

JavaScript code (used on elements that are not generated after page loading)

$('#minor_partners a').click(function() {
    $(this).attr('target', '_blank');
});

JavaScript code (used in elements that are generated after page loading)

$('#minor_partners').on('click', 'a',function() {
    $(this).attr('target', '_blank');
});
    
21.07.2015 / 17:03