Jquery |在“新建”选项卡中打开子文件夹的所有链接

Jquery |在“新建”选项卡中打开子文件夹的所有链接,jquery,subdirectory,Jquery,Subdirectory,我需要在新选项卡中打开Wordpress子文件夹documents的所有URL。例如“*” 场景:当显示目录“documents”中所有帖子的帖子网格时,每个帖子都会在一个新选项卡中打开 我试着编辑外部链接脚本,让它为我工作,但我没有任何进展。我需要使用JQuery/Javascript甚至WP函数来实现这一点 帮助:)您可以使用它为包含documents文件夹的所有锚点附加事件处理程序。 并使用window.open(url,“_blank”)在新选项卡中打开链接: //使用jQuery $(

我需要在新选项卡中打开Wordpress子文件夹documents的所有URL。例如“*”

场景:当显示目录“documents”中所有帖子的帖子网格时,每个帖子都会在一个新选项卡中打开

我试着编辑外部链接脚本,让它为我工作,但我没有任何进展。我需要使用JQuery/Javascript甚至WP函数来实现这一点

帮助:)

您可以使用它为包含documents文件夹的所有锚点附加事件处理程序。 并使用window.open(url,“_blank”)在新选项卡中打开链接:

//使用jQuery
$('a[href*=“documents/”])。在('click',函数(e){
e、 预防默认值();
var win=window.open(this.href,'u blank');
win.focus();
})
//使用javaScript
document.querySelectorAll('a[href*=“documents/”]).forEach(函数(ele,inx){
ele.addEventListener('click',function(){
var e=事件| | window.event;
e、 预防默认值();
var win=window.open(this.href,'u blank');
win.focus();
})
})
您可以使用,以便为包含documents文件夹的所有锚点附加事件处理程序。 并使用window.open(url,“_blank”)在新选项卡中打开链接:

//使用jQuery
$('a[href*=“documents/”])。在('click',函数(e){
e、 预防默认值();
var win=window.open(this.href,'u blank');
win.focus();
})
//使用javaScript
document.querySelectorAll('a[href*=“documents/”]).forEach(函数(ele,inx){
ele.addEventListener('click',function(){
var e=事件| | window.event;
e、 预防默认值();
var win=window.open(this.href,'u blank');
win.focus();
})
})

感谢@gaetanoM帮我解决了这个问题

对于那些有类似问题的人,最终的工作解决方案是:

    // Open all document post types in a new tab
    jQuery(document).ready(function($) {
    $(document).on('click', 'a[href*="documents/"]', function(e) {
    e.preventDefault();
    var win = window.open(this.href, '_blank');
    win.focus();
    })

    });

感谢@gaetanoM帮我解决了这个问题

对于那些有类似问题的人,最终的工作解决方案是:

    // Open all document post types in a new tab
    jQuery(document).ready(function($) {
    $(document).on('click', 'a[href*="documents/"]', function(e) {
    e.preventDefault();
    var win = window.open(this.href, '_blank');
    win.focus();
    })

    });

感谢您的快速回复!感谢您的快速回复!不幸的是,它不适合我。这可能是我做错了。我通过函数文件将其排队。通过Visual Composer post grid元素生成链接是否会有所不同?我正在链接到post type“文档”中的帖子“我从哪里得到了url?您是否包括jQuery库?您是否将代码包装在jQuery ready函数中?如果锚是动态生成的,则需要委托事件处理程序$(document).on('click','a[href*=“documents/”]),函数(e){calling code.jquery.com/jquery-1.10.2.js>,在header single file和functions.php文件中://尝试强制在新选项卡中打开指向文档帖子的链接添加_操作('wp_footer','footer_so_18774457');函数footer_so_18774457(){if(!is_single())return;echo“jQuery(document).ready(function($){$('a[href*='documents/']).on('click',function(e){e.preventDefault();var win=window.open(this.href,'u blank');win.focus();});”感谢您的快速回复!感谢您的快速回复!不幸的是,它不适合我。这可能是我做错了。我通过函数文件将其排队。通过Visual Composer post grid元素生成链接是否会有所不同?我正在链接到post type“文档”中的帖子“这就是我得到url的地方。你是否包含了jQuery库?你是否将代码包装在jQuery ready函数中?如果锚是动态生成的,你需要委托事件处理程序。$(文档)。在('click','a[href*=“documents/”]”上,函数(e){calling code.jQuery.com/jQuery-1.10.2.js“>在页眉单个文件和functions.php文件中://尝试强制在新选项卡中打开指向文档帖子的链接添加操作('wp_footer','footer_so_18774457');函数footer_so_18774457(){if(!is_single())return;echo“jQuery(document).ready(function($){$('a[href*='documents/'))。on('click',函数(e){e.preventDefault();var win=window.open(this.href,'u blank');win.focus();});“;}