Skip to content Skip to sidebar Skip to footer

Websocket Across Pages Javascript

I have implemented a basic websockets client in JS: function connectToNotifServer(){ var conn = new WebSocket('ws://localhost:8080'); conn.onopen = function(e) { alert('Conne

Solution 1:

You can do this by opening the WebSocket connection from a shared background Web worker.

The WebSocket connection will stay open when at least one tab is still active to the given origin (of the shared Web worker).

I know that Chrome and IE11 support opening WebSocket connections from dedicated Web workers. Firefox does not currently. I don't know which browsers support WebSocket connection from shared Web workers (which is what you'd need).

Solution 2:

This wont be any problem. Because every time when page will reload the page will loose the connection and will establish a new connection.

And the answer of your other question "Is there anyway, to make a connection once and use that throughout different pages and page reloads" is no. You can not use the same connection through out the page after page reload.

Solution 3:

You can't keep the connection opened if the user changes pages.

Post a Comment for "Websocket Across Pages Javascript"