Search code examples
javajquerycometcometd

How to avoid calling cometd serversession listener while reloading the page in browser instead of closing the window?


I am working with cometd library for pushing notifications to web page here I am facing one problem i.e., whenever I am reloading (refreshing) the browser page

 ServerSession.addListener(new ServerSession.RemoveListener() {.......} 

this method is calling unfortunately in some browsers how to avoid calling this listener,actually this listener should call whenever window closes or any click event occurs on link,So please help me to achieve this.Thank you


Solution

  • If you want to avoid the calling ServerSession.addListener(new ServerSession.RemoveListener() {.......} while reloading the page in mozilla firefix and opera browsers just comment the $.cometd.disconnect(); and use window.onpagehide instead of window.unload because window.unload will call while refreshing the page in mozilla and opera browsers.It fit for me perfectly.Thank you.