Monday 15 July 2013

javascript - Can an onbeforeunload event complete "too slowly"? What am I missing? -



javascript - Can an onbeforeunload event complete "too slowly"? What am I missing? -

this seems mutual kind of complaint, don't see exact duplicates , more importantly don't see working answers, i'm joining crowd.

i have code does

window.onbeforeunload = function() { pubnub.publish(...); };

to publish message pubnub channel when user leaves current page. it's chat forum, , want publish fact user x no longer in room. (please suppress urge suggest other designs, such having every user send heartbeat; toy project i'm playing with.)

watching channel in browser tab, observe pubnub message gets published 100% of time when i

close tab

and (both yes , no) when i

refresh clicking circley icon in address bar

but apparently never when i

navigate away clicking link navigate away entering new url in address bar refresh entering same url in address bar refresh hitting ⌘r

notice putting return "please don't exit"; in onbeforeunload handler results in flaky publishing: come in same url in address bar , publish happens, come in same url , publish doesn't happen.

is quirk of safari, , if there known workaround? alternatively, pubnub.publish() somehow "too slow" or "too multithreaded" succeed during onbeforeunload event? don't understand how onbeforeunload works.

(for time being, whole code can accessed here, if you're reading question month now, aware that link may dead and/or fixed.)

this our presence feature for. check out here:

http://www.pubnub.com/docs/javascript/overview/presence.html

this way, when "leave" channel, presence scheme can broadcast interested. looking for?

geremy

javascript safari cross-browser pubnub

No comments:

Post a Comment