I have the following php code on my server with Javascript to open windows. When I execute this code in my browser window, it opens the necessary windows. However, if this program is called by another server application (on it's own trigger), the windows do not open as expected in Javascript - any other logic in the code does get executed. For example, if I add a write mySQL table command in the following code, it writes the table when called by an external program but does not open windows locally.
Ideally, I want the program to start executing (and open windows) when called by the external program.
This is the code
<?php
$json='{"stocks":"AMBUACEM,BALRAMCHIN","trigger_prices":"423.55,369.80","triggered_at":"9:44 am","scan_name":"HMA_crossover","scan_url":"hma-crossover-222","alert_name":"HMA crossover","webhook_url":"https:\/\/pundlik.com\/ChartInk\/hmacross.php"}';
$jsonobj= json_decode($json,true);
$stks = explode(",",$jsonobj["stocks"]);
$price = explode(",",$jsonobj["trigger_prices"]);
$tm = explode(",",$jsonobj["triggered_at"]);
$scname = explode(",",$jsonobj["scan_name"]);
$xscrip=$stks[0];
$win1 ="https://kite.zerodha.com/chart/ext/tvc/NSE/";
$win1 .= $xscrip;
$win1 .= '/';
$win1 .= '325121';
$xscrip=$stks[1];
$win2 ="https://kite.zerodha.com/chart/ext/tvc/NSE/";
$win2 .= $xscrip;
$win2 .= '/';
$win2 .= '87297';
?>
<script type="text/JavaScript">
var url = "<?php echo $win1; ?>";
window.open(url)
</script>
<script type="text/JavaScript">
var url = "<?php echo $win2; ?>";
window.open(url)
</script>
What I have tried:
Ideally, the above code should execute and open the windows locally once triggered by the external application. But when the external application calls this code, the window.open() commands do not get executed while any other code is executed, including database updates.
How do I force opening of windows on my client? Alternately, how do I get the code to wait till some PUT input is received from the external site - tried crude methods like a do while loop, etc but they give different errors without the desired results.