• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts action triggered by onUnload event on cloaing a browser

 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All

I want to fire an action when a user closes the browser in struts.
I am calling onbeforeupload() or onunload() of html body for catching closing event of
browser.
Can anyone suggest me how can i call struts action on any of these functions??
I will be very thankful.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any time you want to communicate with a server-side object such as an Action from a client-side javaScript function or event, you must use AJAX to do so. If you don't already know how to code AJAX calls and don't want to spend the time to learn, you might consider using an AJAX framework such as DWR or a JavaScript toolkit such as dojo or scrip.aculo.us.
[ October 18, 2007: Message edited by: Merrill Higginson ]
 
Khushwinder Chahal
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friend
Thanks for your reply.
But do you want to say it is not possible in javascript?
I only want to know the event which can call the struts action..
Anybody other has any idea...
Thanks.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by khushwinder khushwinder:

But do you want to say it is not possible in javascript?

No, I don't mean to say that at all. It is possible to communicate with an action from JavaScript, but only by using the XMLHttpRequest object. When you use this JavaScript object, that's generally referred to as "using AJAX". The rules for using this object are fairly complex and I can't explain in a couple of sentences how to do it. You will have to learn this skill on your own or else use a framework as I mentioned earlier.
Originally posted by khushwinder khushwinder:
I only want to know the event which can call the struts action.

You can make a call to an action from any JavaScript event. The trick is to do it properly.
[ October 18, 2007: Message edited by: Merrill Higginson ]
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Merrill mentions, an Action runs on your web server and JavaScript and events run on the client's computer. Maybe you should explain what you are trying to do. Maybe you don't really need to call an Action and you can implement your code in JavaScript.

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic