What is the best way to make two web pages communicate between each other back and forth?

2.3k views Asked by At

What is the best way to make two web pages communicate between each other back and forth? I will be using HTML and Javascript. Basically I want to login on a web page and I should be able to see who has logged in from the second page. It's just a test app so just need a quick solution.

1

There are 1 answers

4
Cymen On BEST ANSWER

If you just wanted two pages to communicate in the same browser session on the same domain, you could use localStorage -- it's basically a key-value store with some limits on size (rough estimate 5 MB but it varies). An event is fired when you write to localStorage so you can have a listener on one page (and write to it from another page).

However, the constraint of needing to see who has logged in from a second page means JavaScript alone client-side is not going to be able to solve the problem. You'll need something on the server-side that you can poll (or use a push mechanism). You could use JavaScript there to continue to update a page with login data. But it needs to talk to the server to know who logged in.