We help IT Professionals succeed at work.

Pop Up functionality when user leaves a site in jsp

AnithaE
AnithaE asked
on
Can anyone help me on writing an exit pop-up in a jsp page. Req's-  pop-up has to appear whenever an anonymous user leaves the site and if the suppress pop up is in the uri of the user's session, prevent the pop-up from showing. Thank you.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
Exit popups are done with Javascript, generally.  This is a nice site for how to code Javascript exit popups:
http://www.hypergurl.com/popup.html
Basically, you use the OnUnload tag:
<body OnUnLoad="evalForPopup()">
where evalForPopup is a Javascript function which checks some values and either continues with the popup, or not.

In your case, instead of checking the cookie to suppress the popup, you would check the url -- or probably query parameters?

On the other hand, you could generate the page using JSP to either have the OnUnload poup, or not, depending on the information you've stored in the session.

Author

Commented:
Hi, Thanks for those useful Hints. One 2 more question- what is meant by Supress the PopUp and how can it be set in a cookie. Should this Exit Pop Up be made a Session Scope one or a Request Scope one in the JSP page. Thanks
CERTIFIED EXPERT
Top Expert 2007
Commented:
If you looked at the page I gave the link to above, it explained that the writer wanted to suppress the popup so that it only happened once to one person in any one day.  So they set a date-time stamp in their cookie, and check to see if it's today.  In your case, you must have a way for users to ask that they not get the popup, since you said you can tell from their "uri".  So in your case, you want to suppress the popup based on that.

To suppress the popup means that it doesn't pop up.

The suppression does not happen in the cookie, the value that you read in the Javascript function is set in the cookie.  Then in your Javascript function, you check if there's a value in the cookie that says "do not do exit popup" and you don't do the exit popup.

>Should this Exit Pop Up be made a Session Scope one or a Request Scope one in the JSP page.
Exit popups are handled by Javascript.  So the most that a JSP page could do would be to read the "no popups" value in the cookie, and generate the HTML for the page without the exit popup code.  There's no direct relationship between the cookie and whether bean attributes are in session scope or request scope.  

If you mean should you set a bean value in your code with the cookie information (not really necessary since it's in the cookie, but you could do it for convenience) then I think you have to check it with every page display, which would be Request scope.   But it would work to set it for session, since the cookie would live that long, too.

Author

Commented:
Thank you so much. I did read the stuff in that link but doing so many things it went over my head! I really thank for that prompt and consice answer.
CERTIFIED EXPERT
Top Expert 2007

Commented:
You're welcome.  If you need any help with the JSP code, or Javascript code, post another question.

The JSP group is here:
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/

Explore More ContentExplore courses, solutions, and other research materials related to this topic.