I am writing a simple page that listens to SignalR events that once detected will perform an ajax request to a web service on our servers.
Once that ajax request is complete, a url is returned with a custom URI scheme that once reirected to, will open up a custom program installed on the client machine without navigating away from the main page. This is achieved by calling window.location = url;
in the success callback of the ajax request.
This method works find on the other areas of our website that we are using this, making multiple ajax requests and redirecting in the callback work as it should by sending commands to our program without affecting the main page.
The new page I am creating however uses SignalR to decide when to make these same ajax requests but it is disconnecting itself upon the first redirect. I find the following message in the javascript console which I understand is quite normal to see when a page is unloaded but in the case of my scenario, the calling page is never actually unloaded: The connection to ... was interrupted while the page was loading.
I am looking for a way to stop SignalR from disconnecting itself on the redirect as this causes further redirects to fail until SignalR re-establishes the connection.
SignalR tries to gracefully stop any ongoing connections when the user navigates away from the page. SignalR does this by binding to window unload events using jQuery. Typically this is done using
$(window).bind("unload", //...
, but in Firefox$(window).bind("beforeunload", //...
is also used.Assuming you don't attach to either of these events yourself, you can prevent this behavior by unbinding the unload and beforeunload event handlers bound by SignalR using jQuery: