Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress opens link in same window despite target="_blank"

On my page http://verein-iks.eu/dev/ I have a Facebook button on the top-right. If I click the button, I get forwarded to a Facebook page. However, the link is opened in the same window. I want it to be opened in a new window/tab. Hence, I use target='_blank' in the HTML code. Still, the link gets opened in the same window! Why?

When checking the source code (Ctrl+U in Firefox and Chrome) of the page, you can see on line 166 that the target is indeed set to target="_blank". Strangely, when I inspect the element (in Chrome via Ctrl+Shift+I), the target="_blank" property seems to have disappeared.

like image 924
beta Avatar asked Sep 12 '26 09:09

beta


2 Answers

If you have wp accessibility plugin activated in your wordpress installation there is a checkbox in wp accessibility settings, under Miscellaneous Accessibility Settings which called Remove target attribute from links. Uncheck it and everything will by fine :)

like image 51
John Gagiatsos Avatar answered Sep 14 '26 03:09

John Gagiatsos


In the footer of your DOM, there is a <script> that is removing the target attribute from all links...

<script type="text/javascript">
//<![CDATA[
(function( $ ) { 'use strict';

    $('a').removeAttr('target');    //This will remove the target attribute from all links on page load   

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

}(jQuery));
//]]>
</script>

The reason you see the attribute when viewing the source is due to the fact that the source is what was received from the server. Inspect Element is a live view of what happens with the DOM, so it renders the result of the executed JS.

like image 31
Chris Avatar answered Sep 14 '26 03:09

Chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!