Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

show popup onClose page/tab

Posted on 2008-10-15
4
Medium Priority
?
612 Views
Last Modified: 2012-06-27
I need some javascript that will show a popup after user has closed the window(or just before the closing). i have found woring exampes of onUnload onbeforeUnload, but i cant make this works.
Please help.

thanks
0
Comment
Question by:starbones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 22728129
What type of popup?  The use of onbeforeunload is limited.  It basically will just provide a way for a "confirm" type alert to appear.  You can specify the message so this may be all you need but if you mean a popup window or some element then you won't be able to do this.
If the alert/confirm is what you want then specify the message like ...
window.onbeforeunload = function() { return "Are you sure you want to go?"; };
Let me know if you have a question.
bol
0
 

Author Comment

by:starbones
ID: 22728559

It needs to open a popup with survey(so people can select why they leave the mid-order process. So it needs to be shown when user clicks on exit button or when trying to go(browse) to another site without finishing order procedure.

if its not possible to open new popup window, i guess i will have to use onbeforeunload, but then how can i check if user is trying to leave to another domain and show the alert? If they just try to browse to another page of my site, then i should display the aert dialog box.

thanks
0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 720 total points
ID: 22728607
Most methods that try to tell if a person is just going to another page on your site use a "switch" or variable that is true/false.  By default the value is one that would cause the confirm.  Each link on the page is set up to change that value to the value that would NOT cause the message.  For example ...
var goingOut = true;
function leaving() {
    if (!goingOut) return false;
    return "Are you sure?";
}
window.onbeforeunload = leaving;
Then each link would have some thing like ...
<a href="thenewpage.htm" onclick="goingOut = false;">Another page</a>
Keep in mind what I said about the onbeforeunload event though.  That event is unique and can't be used for a popup or script that would "hold" the page while a form, etc is completed.  The alert type confirm will appear so a user can confirm they want to go and you can set the message but you can't do the popup, etc.  Let me know if you have a question or need more info.
bol
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 23175315
I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

636 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