How to create an interaction between 3 pages?

Asked

Viewed 119 times

0

Such interaction will work as a type of remote control, exemplifying would be something like: Page A, B and C

  • On page A the user has access to certain commands.
  • Page B is responsible for receiving and processing such commands.
  • And page C will be the page that suffers the action.

How would this interaction work? Will I need any gallery besides jQuery? If possible I would like an example of how it could be done.

A practical example would be:

Page A:

<a href="#">clique aqui</a>

Page B: Detects click on element

Page C:

alert("O elemento foi clicado");

The simplest way to explain it would be this.

  • One way is, I believe, not so complex, to use web sockets. Do you have at least one command and what would this processing be on page B? For example, explain a command, what should be on page A, what should be processed on page B, and what should be on page C.

  • I changed the question with a very simple example, so I can already have the basis to do what I need.

  • Doubt: should page B necessarily exist? I don’t see why it should do this interface. The communication between A and C would be more interesting, perhaps.

  • I pictured page B as some js script from page C, but if it can be a solution without it, there are no problems, page A will be on mobile, and C on the user’s desktop, I pictured B as the one that connects both.

1 answer

0

I believe that the interaction between these pages would be better in the server-side instead of trying to do client-side javascript.

You can store the results of these commands from page A on localStorage or sessionStorage, and get them on page B. Page B does what must be done and passes the result of operations to page C. Page C then returns to the user whether the operation was a success or not. There is one problem: this solution only works in one device, since the localStorage and the sessionStorage are unique to the browser’s Javascript engine and cannot be shared.

This is very similar to the MVC standard, but certainly only Javascript on client-side is not the best way to implement it. I recommend you take a look at some programming language that can run servers like PHP, Ruby or Java. If you want to continue using Javascript, I recommend Nodejs to be able to use Javascript on the server as well.

Seeing from your comments, you can make two pages:

  1. The page on the phone can send a command to the server;
  2. The server reads this command;
  3. Page B is periodically (every 5-10 seconds) asking the server for the result of the command. When this changes, the page changes its state.

This would be one of the many solutions that exist for your problem, and it is certainly not the best. I suggest you explain your problem a little better, and what more detail do you want to do.

  • 5-10 seconds would be a very large interval, I want to create a type of remote control for my video player, so the user can manipulate actions like play/pause forward, back, exchange videos on mobile.

  • As your situation is local, then the delay may be lower (0.25 - 1 second). Another possibility is to delete page B and keep only page A, and make a common program to listen to these commands. They would run as a server but not serve pages; they would only listen to a port and wait for a command from you to change the player’s state.

  • I intend to apply this method to an online site William, it would be possible something of the type using the user’s network?

  • If it is online, the way is to use Websockets. But you would still need the IP of the user’s machine on its network.

Browser other questions tagged

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