尽管 target="_blank",WordPress 在相同的 window 中打开 link

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

在我的页面上 http://verein-iks.eu/dev/ 我的右上角有一个 Facebook 按钮。如果单击该按钮,我将转到 Facebook 页面。但是,link 是在相同的 window 中打开的。我希望它在新 window/tab 中打开。因此,我在 HTML 代码中使用 target='_blank'。尽管如此,link 还是在 中打开了 window!为什么?

查看页面源代码(Ctrl+U在Firefox和Chrome)时,可以看到在第 166 行,目标确实设置为 target="_blank"。奇怪的是,当我检查元素时(在 Chrome 中通过 Ctrl+Shift+I ), target="_blank" 属性 好像消失了.

在您 DOM 的页脚中,有一个 <script> 从所有链接中删除目标属性...

<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>

您在查看源时看到属性的原因是源是从服务器接收到的。 Inspect Element 是 DOM 所发生情况的实时视图,因此它呈现执行 JS 的结果。

如果您在 wordpress 安装中激活了 wp 辅助功能插件,则在 其他辅助功能设置 下的 wp 辅助功能设置中有一个复选框,它调用了 Remove target attribute from链接。取消选中它,一切都会好的:)