Problem with Onunload event.

Recently I put a question regarding HttpSession invalidation when user jumps to otherURL. I got a answer but still I am facing some problems.

What I did was,  I have two frames in one page. In one of the frame I have coded java script like this.

                 <script language="JavaScript">
                 var leaving = false;

 <body onUnload='if (!leaving) document.forms["search"].submit()'>
                 <form name=search action="/servlet/Logout" method="GET">
                 <input type="hidden" name="Invalidate" value="true">

                  I have servlet(Logout)  which Invalidate the HttpSession.

The problem is,  When I jump to other URL like or from my application/website  the onUnload event is invoking the servlet and It displaying a empty page as responce from the server. In my browser location  also It displaying my servlet path.

But I don't want this.  onUnload has to invoke the servlet and at  the same time the or page has to be displayed. I should not get any responce from my servlet.

Is there any way to do this?

Thanks in advance.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan LouwerensSoftware EngineerCommented:
I'm pulling this all from memory, so please forgive me if I'm off, but I remember there being codes you could return that specifies what the result of the servlet does (for example 404 is one of those codes, 404 being page not found). There are codes that specify that there are no results from the servlet, and even ones that specify that the page should not be redrawn after calling the servlet
gnagabandiAuthor Commented:
Hi jlouwere, thank you. It is working. I coded like this.

//No content for 204.

It does not return enything.  But  still I could not able resolve my entire problem..
Say I jumped to MSN.COM from my application. During this process the onUnload event invoking session invalidate program and there is nothing displayed ( with the help of above code)  in the browser window. In the browser location the URL is still there. If I hit enter one more time  only,  the msn homepage is displayed.

The first hit itself has to display the msn home page.  Any help will be appreciated.

Jan LouwerensSoftware EngineerCommented:
oh wow... I'm glad my sparse reflections actually helped =)
do you have any way of knowing what the destination URL is in your servlet? or maybe even in the javascript in the onUnload function?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

gnagabandiAuthor Commented:
I tried with window.location.url but it capturing the application url (like getRemoteHost), not the destination URL.

Jan LouwerensSoftware EngineerCommented:
hmmmm... I dunno... perhaps you can try this:

in you onUnload function, create a new small HTML document with the form in it and use onLoad to do the same thing as the onUnload does now. in your current onUnload, use to creat a new window with the new HTML file with the form in it. (which will submit the form as soon as it loads). Then, perhaps, to clean up, you can make the servlet actually return some HTML with javascript that can close the window...

I know this is kinda complicated, and an ugly hack, but it just might work...
gnagabandiAuthor Commented:

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.