<form id="frm_1" name="frm_1" target="_self" method="GET" action="local_page.php" >
</form>
<form id="tgt_1" name="tgt_1" target="_blank" method="POST" action="http://*.com/" >
</form>
<a onclick="test(event, '1'); " href="#" >Click Here</a>
<script>
function test(event, id){
document.getElementById("frm_"+id).submit;
document.getElementById("tgt_"+id).submit;
}
</script>
Is it possible to open a new tab/window and change the current page ?
是否可以打开新的选项卡/窗口并更改当前页面?
4 个解决方案
#1
1
As far as I know, it's not possible to submit two forms at once. Since you're using PHP however, why not take a look at the cURL library? It lets you send POST and GET requests and parse the results in PHP.
据我所知,一次提交两张表格是不可能的。既然你正在使用PHP,为什么不看看cURL库呢?它允许您发送POST和GET请求并在PHP中解析结果。
To answer the question in the title, if you simply want to open two pages with one click, you could do it like this (excuse the inline javascript):
要回答标题中的问题,如果您只想一次打开两个页面,就可以这样做(请原谅内联javascript):
<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>
#2
1
<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://*.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>
tgt kept as source of target url, could be array or attribute. Without setyTimeout() browser stays on current page (FF/IE).
tgt保留为目标url的源,可以是数组或属性。没有setyTimeout()浏览器停留在当前页面(FF / IE)。
#3
0
You should use the window.open to open the new page and then submit the tabchange e.g.
您应该使用window.open打开新页面,然后提交tabchange,例如
<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://*.com/", "_blank");
document.getElementById("tgt_"+id).submit();
}
</script>
#4
0
Use the ‘target’ attribute on the form elements to make them submit to eg. a new window or an iframe, without reloading the current page (breaking any other form submissions).
使用表单元素上的“target”属性将它们提交给例如。一个新窗口或一个iframe,无需重新加载当前页面(打破任何其他表单提交)。
Your a.onclick should also return false to stop the href link being followed. Really this should be a button not a link.
您的a.onclick也应返回false以停止跟踪href链接。真的,这应该是一个按钮而不是一个链接。
Avoid this sort of stuff unless you've got a specific good reason. Depending on what you're actually trying to do there is usually a better way.
除非你有一个特定的理由,否则避免使用这类东西。根据您实际尝试的内容,通常有更好的方法。
#1
1
As far as I know, it's not possible to submit two forms at once. Since you're using PHP however, why not take a look at the cURL library? It lets you send POST and GET requests and parse the results in PHP.
据我所知,一次提交两张表格是不可能的。既然你正在使用PHP,为什么不看看cURL库呢?它允许您发送POST和GET请求并在PHP中解析结果。
To answer the question in the title, if you simply want to open two pages with one click, you could do it like this (excuse the inline javascript):
要回答标题中的问题,如果您只想一次打开两个页面,就可以这样做(请原谅内联javascript):
<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>
#2
1
<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://*.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>
tgt kept as source of target url, could be array or attribute. Without setyTimeout() browser stays on current page (FF/IE).
tgt保留为目标url的源,可以是数组或属性。没有setyTimeout()浏览器停留在当前页面(FF / IE)。
#3
0
You should use the window.open to open the new page and then submit the tabchange e.g.
您应该使用window.open打开新页面,然后提交tabchange,例如
<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://*.com/", "_blank");
document.getElementById("tgt_"+id).submit();
}
</script>
#4
0
Use the ‘target’ attribute on the form elements to make them submit to eg. a new window or an iframe, without reloading the current page (breaking any other form submissions).
使用表单元素上的“target”属性将它们提交给例如。一个新窗口或一个iframe,无需重新加载当前页面(打破任何其他表单提交)。
Your a.onclick should also return false to stop the href link being followed. Really this should be a button not a link.
您的a.onclick也应返回false以停止跟踪href链接。真的,这应该是一个按钮而不是一个链接。
Avoid this sort of stuff unless you've got a specific good reason. Depending on what you're actually trying to do there is usually a better way.
除非你有一个特定的理由,否则避免使用这类东西。根据您实际尝试的内容,通常有更好的方法。