[Webinar] Streamline your web hosting managementRegister Today


Pop Up functionality when user leaves a site in jsp

Posted on 2008-01-25
Medium Priority
Last Modified: 2011-10-03
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.
Question by:AnithaE
  • 3
  • 2
LVL 27

Expert Comment

ID: 20745355
Exit popups are done with Javascript, generally.  This is a nice site for how to code Javascript exit popups:
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 Comment

ID: 20746658
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
LVL 27

Accepted Solution

mrcoffee365 earned 2000 total points
ID: 20746754
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 Closing Comment

ID: 31425010
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.
LVL 27

Expert Comment

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

The JSP group is here:

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question