javascript - How to open new two tabs in PHP using header - Stack Overflow

I'm trying to open a new tab with Php,header("location:print_register.php?recpt_no=".$re

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 badges
Add a ment  | 

4 Answers 4

Reset to default 2

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./" 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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745622724a4636619.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信