admin管理员组文章数量:1434909
I'm trying to open a new tab with Php,
header("location:print_register.php?recpt_no=".$recpt_no);
like this i need to open new two tab like this
header("location:print_register.php?recpt_no=".$recpt_no);
header("location:print_generate.php?recpt_no=".$recpt_no);
it need to open new two tab with passing values
I'm trying to open a new tab with Php,
header("location:print_register.php?recpt_no=".$recpt_no);
like this i need to open new two tab like this
header("location:print_register.php?recpt_no=".$recpt_no);
header("location:print_generate.php?recpt_no=".$recpt_no);
it need to open new two tab with passing values
Share Improve this question edited Jan 27, 2015 at 16:29 bcesars 1,0101 gold badge17 silver badges36 bronze badges asked Jan 27, 2015 at 15:44 parthibanparthiban 251 silver badge8 bronze badges4 Answers
Reset to default 2It is impossible to specify a window to open as a tab. Whether it opens as a new tab or a new window is entirely dependent upon the browser and its configuration. The best way to look at these situation is to not distinguish a tab from a window and move on from there.
Having said that, as others have already mentioned, it is impossible to open a new window via PHP. The header()
function will do nothing more than a redirect of the current window. You need to have this occur via a standard link
<a href="http://www.google./" target="_new" />
or JavaScript
window.open('http://www.google./');
In your particular case, you want to launch two, so you can do this (assuming you can use a link) by bining the two
<a href="http://www.google./" target="_new" onclick="javascript:window.open('http://www.stackoverflow./')" />
or launching both via JavaScript. Here's an example that will allow you to store target addresses in an array and launch them all:
window.onload = function() {
var links = new Array('http://www.google./', 'http://www.stackoverflow./');
for(var i = 0; i < links.length; i++) {
window.open(links[i]);
}
}
The links do not need to be absolute, so you can use relative paths such as ./print_register.php?recpt_no=
.
Now, since you're pulling part of the address from the PHP, things get a little more plicated, but not by much. You, basically, just need to use the PHP to plete the rendered JavaScript:
<?php
$recpt_no = 'RN426762';
?>
<html>
<head>
<script>
window.onload = function() {
var links = new Array('./print_register.php?recpt_no=<?php echo $recpt_no; ?>', 'http://www.stackoverflow./');
for(var i = 0; i < links.length; i++) {
window.open(links[i]);
}
}
</script>
</head>
<body>
...
</body>
</html>
You don't need to put the entire script into a PHP echo
. Instead, write the code normal and echo
the PHP variables where you need it. It'll keep the PHP-side of the code cleaner, and help a little with the performance, but probably not noticeable.
I hope this helps. ^^
JSFiddles
- Link: http://jsfiddle/zLh3dusx/
- JavaScript: http://jsfiddle/89boc383/
- Combined: http://jsfiddle/b9zne07r/
- JavaScript Array: http://jsfiddle/9ohLxxLo/
With header it's just not possible. Header will redirect you to a page.
Something like this would work:
<a href='xy.php' target='_blank'>text</a>
PHP cannot do this, but you can do something very similar with JavaScript.
I have acplished this before using jQuery, with a link and a simple 100ms timeout.
Checkout.
http://jsfiddle/hw3t1syz/
finally me itself got anwser
echo "<script type='text/javascript'>
window.open( '/print_register.php?recpt_no=$recpt_no' )
</script>";
use it it will open new tab
本文标签: javascriptHow to open new two tabs in PHP using headerStack Overflow
版权声明:本文标题:javascript - How to open new two tabs in PHP using header - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745622723a2666784.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论