问题
Is there some way to end a conversation in Seam 2 when the user leaves the page? I know, that I can of course end a conversation in the navigation rules( see this post), but I want to end a conversation when the user enters an url in the address bar of the browser.
Could this be achieved via Javascript (for example with onbeforeunload)? But how to stop a conversation via javascript?
回答1:
I want to end a conversation when the user enters an url in the address bar of the browser.
Could this be achieved via Javascript (for example with onbeforeunload)? But how to stop a conversation via javascript?
You could use JavaScript to implement an onbeforeunload
event and use AJAX to communicate the user leaving to the site and end all your conversations. However, I don't recommend you this solution because you cannot rely on a event happening on the browser, Javascript is not a good option, since you can disable it client-side (Not only that, but the browser may crash, the network connection may drop, etc..)
I think an alternative aproach to do this is by setting a seam conversation timeout
on the server. You can try and reduce the timeout in order to close inactive conversation faster, when the user leave your page.
Configuring the conversation-timeout period can be accomplished through the following in your components.xml
:
<core:manager conversation-timeout="700000" />
Notice that conversation-timeout only affects background
conversations, foreground
conversation will only timeout when the session times out which is relevant for your requirements.
More information about conversation time out can be found in this article.
来源:https://stackoverflow.com/questions/7599288/end-conversation-in-seam-when-the-user-leaves-the-page