简体   繁体   English

target =“ _ blank”无法打开新标签

[英]target=“_blank” does not open a new tab

$description = $this->t('A user-defined date format. See the <a href="http://php.net/manual/function.date.php" target="_blank">PHP </a> for available options.');    

This code does not open the link in a new tab, instead it opens on the same tab. 此代码不会在新标签页中打开链接,而是在同一标签页上打开。 is there a way I can fix this code? 有什么办法可以修复此代码? Or is there an alternate to target="_blank" or to open a URL in a new tab? 还是可以使用target="_blank"的替代方法或在新标签页中打开URL?

You can use jQuery : 您可以使用jQuery:

add an ID to the ancher (here is id="myAnchor") : 向ancher添加一个ID(此处为id =“ myAnchor”):

$(document).on('click', 'a#myAnchor', function(e){ 
    e.preventDefault(); 
    var url = $(this).attr('href'); 
    window.open(url, '_blank');
});

use this for new tab in js 将此用于js中的新标签页

    <script> 
    window.open('http://testsite.com, "_blank");
    </script>
or
    <a href="javascript:void(0);" class="webMnu" onclick="window.open('http://testsite.com','plain');">Enroll</a>

Check your page source. 检查您的页面来源。 If in source you can also see target="_blank" then it means that action is overridden with JavaScript so you should fix JS. 如果在源代码中还可以看到target="_blank"则表示该动作已被JavaScript覆盖,因此您应该修复JS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM