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