How to update another page that is open in PHP, javascript or jquery

Asked

Viewed 875 times

1

Good afternoon, everyone!

I’m new to programming.

Good! I would like to know how to update (refresh) another that is open through a function be it in php, javascript or jquery.

Example: I have a 01.php page that contains an input and a buttom. When you click on the button, it updates the 02.php page that will be open.

Thank you in advance!

2 answers

1


Hi to reload a browser tab first you need to grab the open window reference with function window.open();.

Example, your JS:

    var url = "https://www.google.com/search?source=hp&ei=1eefXJ7dFtrF5OUPjKer4Ag&q=random+number&oq=random+num&gs_l=psy-ab.1.0.0i131j0l2j0i203l2j0l5.44842.46396..47369...2.0..0.179.1255.0j11......0....1..gws-wiz.....0..35i39j0i67j0i10.KgraaLNVsIA";
    var childWindow = window.open(url);

For testing:

<input type="button" onclick="childWindow.location = url;" value="Reload Popup Window">

Do not use childWindow.location.reload(); as mentioned because browsers block access Cross Origin instead use childWindow.location = url; as I did. You can also call the function childWindow.close(); to close the window.

0

Unfortunately this is not possible if you did not open the tab.

The way to update the page would be through a window.location.reload() in Javascript. However, the control of tabs is completely in the hands of the browser if the user opened these tabs on his own.

Now, the simplest way to maintain control over one of the tabs is by opening through the Javascript itself inside the page by clicking on the link:

const janela = window.open('url', '_blank')
janela.location.reload()

See that you now have control of the tab through the variable janela, but this is not guaranteed to open a tab, since the full control of tabs and windows is done by the browser and each implements the _blank differently.

Still, be careful because you will only be able to control the other pages from one original page, which opened the others.

See also:

  • 1

    You can update a tab even if you haven’t opened it, as long as that tab is from the same domain. You can put an Event Listener on window to respond to changes in localStorage. If a tab modifies the localStorage, the other tabs capture the event, and can perform a function according to the received event.

  • But then you are assuming that it will modify the Torage locale. In case you are creating an event in something that does not belong to the window so that when the event happens, you have a e that points to the window that created the event so that you can manipulate it. I personally think this is a bit of a scam...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.