Solved

show popup onClose page/tab

Posted on 2008-10-15
4
599 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
  • 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 180 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding 1 the value of input "text" every 3 seconds 5 33
Asp response.write to clients 6 34
Triple line in an alert message 4 24
Compute age Html 2 27
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'…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

733 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