使用任何可能的方法在新选项卡(而不是新窗口)中打开

时间:2014-04-18 15:24:15

标签: javascript php jquery tabs

我知道像我这样有很多重复的问题,但我找不到任何解决方案。我在代码中打开一个新选项卡时遇到问题。我想打开一个新标签 - 而不是一个窗口 - 没有点击任何按钮,我需要它自动运行。

这是我的代码,但它打开了一个新窗口,而不是新的点击。

代码:

if (isset($_POST['check'])){
  ?><script>window.open('reports/education_efficacy.php','_blank');</script><?php
}

元刷新版本: (它重定向到同一页面中的目标页面,我想知道有没有办法重定向到新标签?)

if (isset($_POST['check'])){
  echo "<meta http-equiv=\"refresh\" content=\"0; URL=javascript:window.open('reports/relation_with_health.php\','_new');\">";
}

2 个答案:

答案 0 :(得分:0)

试试这个:

window.open('reports/relation_with_health.php\','_blank')

答案 1 :(得分:0)

打开一个新的水龙头并保持当前标签(ctrl + click)功能,如。

java代码:

<script>
        document.getElementById("test").addEventListener("click", openNewBackgroundTab, false);

        function openNewBackgroundTab(url){
            var a = document.createElement("a");
             a.href = url;
            var evt = document.createEvent("MouseEvents");    
            evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
            a.dispatchEvent(evt);
        }
    </script>

html代码:

<a href="#" id="test" onclick="openNewBackgroundTab('reports/education_efficacy.php')" >education efficacy</a>