JS / jQuery不支持以编程方式“单击”链接的默认行为。
您可以做的就是创建一个表单并提交。这样,您就不必使用window.location或了window.open,它们通常被浏览器阻止为不需要的弹出窗口。
该脚本有2种不同的方法:一种尝试打开3个新标签页/窗口(它仅在IE和Chrome中打开1个,以下提供更多信息),另一种在链接点击时触发自定义事件。
方法如下:
的HTML
<html>
<head>
    <script src="jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="script.js" type="text/javascript"></script>
</head>
<body>
    <button id="testbtn">Test</button><br><br>
    <a href="https://google.nl">GOOGLE</a><br>
    <a href="http://en.wikipedia.org/wiki/Main_Page">WIKI</a><br>
    <a href="https://stackoverflow.com/">SO</a>
</body>
</html>
jQuery(script.js)
$(function()
{ 
    // Try to open all 3 links by pressing the button
    // - Firefox opens all 3 links
    // - Chrome only opens 1 of them without popup warning
    // - IE only opens 1 of them WITH popup warning
    $("#testbtn").on("click", function()
    {
        $("a").each(function()
        {
            var form = $("<form></form>");
            form.attr(
            {
                id     : "formform",
                action : $(this).attr("href"),
                method : "GET",
                // Open in new window/tab
                target : "_blank"
            });
            $("body").append(form);
            $("#formform").submit();
            $("#formform").remove();
        });
    });
    // Or click the link and fire a custom event 
    // (open your own window without following the link itself)
    $("a").on("click", function()
    {
        var form = $("<form></form>");
        form.attr(
        {
            id     : "formform",
            // The location given in the link itself
            action : $(this).attr("href"), 
            method : "GET",
            // Open in new window/tab
            target : "_blank"              
        });
        $("body").append(form);
        $("#formform").submit();
        $("#formform").remove();
        // Prevent the link from opening normally
        return false;
    });
});
它对每个链接元素的作用是:
- 建立表格
 
- 给它属性
 
- 将其附加到DOM,以便可以提交
 
- 提交
 
- 从DOM中删除表单,删除所有痕迹*插入邪恶的笑声*
 
现在,您有一个新的选项卡/窗口加载"https://google.nl"(或您想要的任何URL,只需替换它)。不幸的是,当您尝试以这种方式打开多个窗口Popup blocked时,尝试打开第二个窗口时仍会收到一个消息栏(第一个窗口仍处于打开状态)。
有关如何使用此方法的更多信息,请参见: 
不使用window.open或打开新窗口/标签window.location.href