Javascript 如何打开新选项卡并更改当前页面 功能测试(事件,id){ 文档.getElementById(“frm_3;”+id).提交; document.getElementById(“tgt_”+id)。提交; }

Javascript 如何打开新选项卡并更改当前页面 功能测试(事件,id){ 文档.getElementById(“frm_3;”+id).提交; document.getElementById(“tgt_”+id)。提交; },javascript,Javascript,是否可以打开新的选项卡/窗口并更改当前页面?据我所知,不可能同时提交两份表格。既然您使用的是PHP,为什么不看看这个库呢?它允许您发送POST和GET请求,并在PHP中解析结果 要回答标题中的问题,如果您只想通过单击打开两个页面,您可以这样做(请原谅内联javascript): 您应该使用window.open打开新页面,然后提交选项卡更改,例如 <a href="http://www.google.com" target="_blank" onclick="doc

是否可以打开新的选项卡/窗口并更改当前页面?

据我所知,不可能同时提交两份表格。既然您使用的是PHP,为什么不看看这个库呢?它允许您发送POST和GET请求,并在PHP中解析结果

要回答标题中的问题,如果您只想通过单击打开两个页面,您可以这样做(请原谅内联javascript):


您应该使用window.open打开新页面,然后提交选项卡更改,例如

<a
    href="http://www.google.com"
    target="_blank"
    onclick="document.location.href='http://www.yahoo.com'"
>Click here to open Google in a new window and yahoo in this window</a>

功能测试(事件,id){
窗口打开(“http://stackoverflow.com/“,”空白“);
document.getElementById(“tgt_216;”+id).submit();
}

使用表单元素上的“target”属性,使其提交到新窗口或iframe,而无需重新加载当前页面(中断任何其他表单提交)

您的a.onclick也应返回false以停止跟随href链接。实际上,这应该是一个按钮,而不是一个链接

除非你有明确的理由,否则不要做这种事。根据您实际要做的事情,通常会有更好的方法。


<form id="frm_1" name="frm_1" target="_self" method="GET" action="local_page.php" >
</form>
<a onclick="test(event, '1'); " href="#" >Click Here</a>
<script>
    function test(event, id){
        window.open("http://stackoverflow.com/", "_blank");
        document.getElementById("tgt_"+id).submit();
    }
</script>

仍在努力。
的用法是让浏览器状态栏显示href url。当href参数为
href=“local_page.php”
且仅为
document.getElementById(“tgt_”+id”)。提交时,我的原始代码可以工作存在。但这意味着我无法将所选选项的任何信息发布到本地页面。在这种情况下,使用GET和追加参数不是一个选项。
<form id="frm_1" name="frm_1" target="_self" method="GET" action="local_page.php" >
</form>
<a onclick="test(event, '1'); " href="#" >Click Here</a>
<script>
    function test(event, id){
        window.open("http://stackoverflow.com/", "_blank");
        document.getElementById("tgt_"+id).submit();
    }
</script>
<form id="frm_1" name="frm_1" target="_self" method="POST" action="local_page.php" >
<input type="hidden" name="vital_param" value="<?= $something ?>">
</form>

<form id="tgt_1" name="tgt_1" target="_blank" method="POST" action="http://stackoverflow.com/" >
</form>

<button type="submit" onclick="test(event, '1'); " >Click Here</button>

<script>
    function test(event, id){
    window.open( document.getElementById("tgt_"+id).action, "_blank");
    setTimeout('document.getElementById("frm_'+id+'").submit();', 1000);

    return true;
    }
</script>