I would like to create a php file (lets call it master.php) that executes automaticlly a series of scripts in a new tab. Every script listed should be executed in a different tab. I tried using header(location), however it can only be used to redirect once. Any idea?
4 Answers
What you want goes beyond the scope of php. You have to use javascript to control the logic among the browser's tabs you want to launch.
From php, you should generate the proper javascript code to do that, in particular take a look at the javascript function window.open

- 2,770
- 14
- 21
You can create a hyperlink as below:
<body onload="document.getElementById('runScripts').click()">
<a id="runScripts" href="script1.php" target="_blank" onclick="window.open('script2.php');window.open('script3.php')">Click Here</a>

- 3,976
- 4
- 25
- 39
-
This is a good idea but you still have to click to hyperlink to open the scripts. – mat Nov 09 '12 at 19:50
If master.php returns the first page, and then you could use javascript to open the other pages. Please note that this does not have 100% browser support.
<html>
<head>
<script type="text/javascript">
window.open('page2.php','_newtab1');
window.open('page3.php','_newtab2');
window.open('page4.php','_newtab3');
window.open('page5.php','_newtab4');
</script>
</head>
<body>content of first page</body>
</html>
You could also use '_blank' instead of ''newtab'

- 2,041
- 1
- 15
- 20
I would suggest using Javascript to execute the scripts in different tab. However this open new windows and popup option has to be disabled. New tabs are not opened unless user explicitly clicks on an anchor element. The following code is an example from withing a PHP for loop.
window.open("script" + <?php echo
$i ;?>
+ ".php", '_blank');

- 1,436
- 2
- 24
- 34