How to create an interaction between 3 pages?

0

This interaction will work as a type of remote control, exemplifying 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 undergoes the action.

How would this interaction work? Will I need a gallery other than 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 the click on the element

Page C:

alert("O elemento foi clicado");

The simplest way to explain this would be this.

    
asked by anonymous 19.03.2017 / 05:09

1 answer

0

I think the interaction between these pages would work better on server-side instead of trying to do client-side with JavaScript.

You can store the results of these commands from page A in localStorage or sessionStorage , and get them on page B. Page B does what needs to be done and passes the result of operations to page C. The C page then returns to the user whether the operation was successful or not. There is a catch: this solution only works on a single device, since localStorage and sessionStorage are unique to the browser's JavaScript engine and can not be shared.

This closely resembles the MVC standard, but of course only JavaScript on the client-side is not the best way to implement it. I recommend you take a look at some programming language that can run servers such as 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 your comments, you can make two pages:

  • The page that is on the phone can send a command to the server;
  • The server reads this command;
  • 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 certainly not the best. I suggest you explain your problem a little better, and that detail plus what you want to do.

        
    19.03.2017 / 21:06