只需单击一下即可在新选项卡中打开多个链接 [英] Opening multiple links in new tabs with one click

查看:88
本文介绍了只需单击一下即可在新选项卡中打开多个链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些PHP代码:

foreach($moduid as $k=>$mod) {
$random = $k+1; 
echo '<a href="http://mysite.com?y='.$cid.'&t='.$mod.'&s=-2" data-pack="true" id="link'.$random.'">data</a>';
}

和JS代码:

$(document).ready(function() {
var $hash = new Array(); // We create new Array     
$('a').click( function(){ // On each click to <a> element
    if ( $(this).attr("data-pack") == "true" ) { // check wether this is one of the links we use
            $hash[$(this).attr("id")] = $(this).attr("href"); // We add href value into $hash object
            $(this).css("color","green"); // Way to mark selected ones
            $(this).attr("data-pack", "selected"); // Change data-pack property value to selected
            return false; // We don't want to execute this yet
    } else if ( $(this).attr("data-pack") == "selected" ) { // In case you change your mind and want to unselect
            $(this).attr("data-pack", "true"); // Change data-pack property back, thanks to Ambrosia pointing it out in the comment
            $(this).css("color","red"); // We mark it as unset
            delete $hash[$(this).attr("id")]; // Remove it from hash
            return false;
    }
});

$("form").submit( function(){ // After we submit
    for (var i in $hash) { // Go trough $hash
            window.open($hash[i]); // And open window for each member
    }
    return false; // We don't actually want to submit form, just open new windows :)
} );        
});

我使用了其中一些:在多个浏览器窗口/选项卡中打开链接

但是它没有当我点击提交时似乎工作。我并不真正了解JS,并希望有人知道为什么按提交不会在新标签中打开所有这些链接。我正在使用这个jQuery - http://ajax.googleapis .com / ajax / libs / jquery / 1.3 / jquery.min.js

However it doesn't appear to work, when I click submit. I don't really understand JS and was hoping someone would know why pressing submit doesnt open all these links in new tabs. I'm using this jQuery - http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js

它在IE8中工作但不是Firefox或Chrome,我希望它能打开所有链接不仅仅是我选择的链接。所以也许这不是正确的JS工作?

It's working in IE8 but not Firefox nor Chrome, I want it to open all links not just ones I've selected. So perhaps this isnt the right JS for the job?

在Firefox中它只是跟随链接。

In Firefox it just follows the link.

谢谢

推荐答案

取消阻止弹出窗口,您的代码应该可以正常工作。

Go unblock popups and your code should work.

这篇关于只需单击一下即可在新选项卡中打开多个链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆