Question

I am currently using faye for pubsub and am disconnecting the client on the beforeunload event.While it disconnects during tab close during page refresh it throws the following error :

The connection was interrupted while the page was loading

The code is

window.addEventListener('beforeunload',function(event){
  fayeClient.disconnect();
  event.preventDefault();});

Is there a way to stop firefox from closing the connection before the call completes.The above code works perfectly in chrome

Was it helpful?

Solution

How can I prevent a page unload with jQuery?

way down in the comments it says:

event.preventDefault() doesn't work in this case, presumably because modern browsers don't want malicious coders to hijack the window and make it un-closable? – yochannah May 9 '13 at 8:45

I dont believe it is possible to delay it longer then it takes for that code to execute, excluding any async returns and timeouts.

So, to hack this. Call your disconnect, then make a synchronous call to a file which does

<?php
sleep(1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top