How do I share data across multiple browser tab or windows? - ajax

I m currently building a facebook style notification system for my site.
I m using long polling. So, the server sends data if its available and closes the connection.
Now the problem i m facing is that, i want it to share across all open tabs or windows of that browser.
I m using a cookie to detect if a tab is already executing the ajax call, so other tabs will not execute it until the operation of the first tab is complete.
Now what i want is, to have an effective way, so that i can show the data across all open tabs in the form or a small fb style popup box.
The goal is if the last active ajax call has some data, then a small popup box will show up on all open browser tab or windows.
As, a theory i may be able to do it via cookie, but i want to know if there is some better way to do that.
Thanks,
Anjan

Browsers don't let pages talk to other pages. You'd have to make an extension to get around the cookie.
If you're ok with the cookie idea, follow these examples:
For client side access
For PHP access
For NodeJS

Related

CakePHP delete specific session on browser close

I'm trying to set up some logging in my CakePHP application and I want a specific session to delete at browser close, however CakePHP is saving the session somewhere.
What can I do to have only that specific session deleted on browser close?
That's not possible. See javascript detect browser close tab/close browser
If I get you correctly, you want to know when a tab/window is
effectively closed. Well, afaik your only way in Javascript to detect
that kind of stuff are onunload & onbeforeunload events.
Unfortunately (or fortunately?), those events are also fired when you
leave a site over a link or your browsers back button. So this is the
best answer I can give, I don't think you can natively detect a pure
close in Javascript. Correct me if I'm wrong here.

How to share data between two browser windows

In my web application I get some data from server. Then if user want's to see this data visualized in great detail I want to open second browser window and do it there. The problem is with passing the data to be visualized. I don't want to make second request to server. So all I have now is to append this data to the URL to be opened in second window. This of course works but the URL look ugly and the amount of data is very limited. Is there any other way to accomplish this?
You could use a session-value. Save the data into the session when retrieving it from the server, and read it when you open the second browser tab.

Persistant Chat Window? Like Facebook or OkCupid

I saw this question asked here 18 months ago, but without (a correct) answer: Window like facebook chat
Both Facebook and OkCupid have messaging windows which stay open even when you click to another page on their website. Literally the IM window (and friend list, on Facebook) don't so much as flash or "blink" as if they were reloading quickly. If you refresh the website (F5 or such) then the messages will disappear, at least for a moment.
The only thing I can think of is that the entire website never actually changes addresses, but just pushes the new URLs to your browser so it looks like the URL changed, but you never really left the same file.
How are they offering this persistent chat?
My guess is they are using something similar to qjuery-pjax:
https://github.com/defunkt/jquery-pjax
From their docs:
pjax works by grabbing html from your server via ajax and replacing the content of a container on your page with the ajax'd html. It then updates the browser's current url using pushState without reloading your page's layout or any resources (js, css), giving the appearance of a fast, full page load. But really it's just ajax and pushState.
This means clicking a link on the page will load only part for page and leave the chat windows untouched (no flicker). If you hit F5, the browser is initiating the refresh which will not use ajax/pushState. This causes the chat windows to flicker.

How i can track Safari activity from my application

I have to develop an application to monitor Safari activity like all open url , tabs on particular window and loding time of particular url.
I also need to track online streaming that is happening on particular opened htmm page
URL of streaming source, which player is being used for streaming and all other basic information which opened page contains.
I have to develop an application to monitor Safari activity like all open url , tabs on particular window and loding time of particular url.
You can ask Safari for the first two things via AppleScript; the latter is in the Element Inspector, but I'm not sure why you would want it in another application.
I also need to track online streaming that is happening on particular opened htmm page
That's a separate question, so you should post it separately.

Web page expired message in browser

I am implementing a web application using ASP .Net and C#. One of the pages has a requirement that it always needs to be fetched from the server, rather than from the local browser cache. I have been able to achieve this.
We have a back button in the application, which simply invokes javascript:history.back() method. The problem is that when the back button is clicked to navigate to the page which is always to be reloaded from the server, the browser displays a "Web page expired message".
The intent here is to force the browser to reload the page rather than display the web page expired message.
Any help would be highly appreciated. Thanks a ton in advance.
You will probably need to change the implementation to make the browser load the URL explicitly:
window.location.href = 'http://....';
instead of invoking the back button, since the intention of the back button is to get the last page from the cache.
(If browsers would not act that way, they would re-send your form data multiple times when using the back button during a registration process or similar.)
You mean you want to control browser behaviour, which is not possible. I doubt you can solve it that way. You could set the expiration time to a small value (1 minute perhaps?) so that the page is still valid if one navigates back quickly.

Resources