Reputation: 25
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
Upvotes: 0
Views: 6096
Reputation: 1198
It 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.com/" target="_new" />
or JavaScript
window.open('http://www.google.com/');
In your particular case, you want to launch two, so you can do this (assuming you can use a link) by combining the two
<a href="http://www.google.com/" target="_new" onclick="javascript:window.open('http://www.stackoverflow.com/')" />
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.com/', 'http://www.stackoverflow.com/');
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 complicated, but not by much. You, basically, just need to use the PHP to complete 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.com/');
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
Upvotes: 2
Reputation: 28
PHP cannot do this, but you can do something very similar with JavaScript.
I have accomplished this before using jQuery, with a link and a simple 100ms timeout.
Checkout.
http://jsfiddle.net/hw3t1syz/
Upvotes: 1
Reputation: 25
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
Upvotes: 0
Reputation: 59681
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>
Upvotes: 1