0

I am consequently running two php pages in the browser. Two php pages in two tabs of a browser. First php page has a button and Second php page has a Jquery that runs a function when the first php button is pressed.

I want the Jquery that is implemented in Second php page to be notified, such that the Jquery after getting notified that a button has been pressed, will reload the Second php's page (Jquery's current page). I am trying to make the Jquery receive the message from the button press but it seems it's not able to receive any. What am I doing wrong?

DownloadButton.php

<?php
if(isset($_POST['submitGenZip']))
    {

        header('Location:GenerateZip.php');
      
    }

?>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Zip Files</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
</head>
...
...
...
<tr>
            <form action="" method="post" role="form">
                <td>
                    <input type="submit" name="submitGenZip" class="btn btn-primary" value = "Generate Zip" style="float: right;">
                </td>
            </form>
        </tr>
...
...

NotificationPage.php

...
...
...

<script>
$("#submitGenZip").click(function()
{
   $(this).data('clicked', true);
   if($("#submitGenZip").data('clicked'))
    {
        location.reload();
    }
});

</script>
  • 1
    The two pages are independent. You'd have to have the other page polling a database or listening to a websocket or something for this. – ceejayoz Jun 28 '20 at 17:58
  • @ceejayoz so is there a way to send a message from first page to second page after the button is pressed? There could be that I could pass a function across. –  Jun 28 '20 at 17:59
  • 2
    This really seems like an [XY problem](http://xyproblem.info/). Why aren't you just using the default form submit process to do all this? – charlietfl Jun 28 '20 at 18:01
  • @charlietfl yes if it were upto me I would have. But the first page has alot of main things going on so its a must for me that I should reload the Notification php page. –  Jun 28 '20 at 18:03
  • So submit the form... process the form data with php and send the same page back – charlietfl Jun 28 '20 at 18:04
  • @charlietfl the submit form in first php page downloads files after the button is pressed and when this happens, the NotificationPage.php should receive this message that the user has pressed the button. I have to run this in a new window yes. –  Jun 28 '20 at 18:05
  • Sounds really flimsy to me. There is no Notification.php page if you relead the existing one. If form is submitted you can track it in session or database. What am I missing here? – charlietfl Jun 28 '20 at 18:07
  • Yes I could load the NotificationPage.php once the form is submitted, I was however looking for a way to send across a message between two active php files. –  Jun 28 '20 at 18:09
  • @charlietfl sorry about that. I have updated my question. I am basically running these two phps concurrently. –  Jun 28 '20 at 18:17
  • Oh... in two tabs, that would change a lot of things not previously explained? If that's the case you can use `postMessage` API or Storage events API to communicate between the two windows – charlietfl Jun 28 '20 at 18:18
  • @charlietfl yes sorry about that. Could you please give me an example of how its done? –  Jun 28 '20 at 18:19
  • Read the docs for both of those API's. The MDN docs are the best ... google MDN postMessage or MDN storage events – charlietfl Jun 28 '20 at 18:20
  • You could be interested in this: [communicate-between-two-pages-tabs](https://stackoverflow.com/questions/48390382/communicate-between-two-pages-tabs/48392467#48392467) – Roko C. Buljan Jun 28 '20 at 22:53

0 Answers0