• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

show popup onClose page/tab

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
starbones
Asked:
starbones
  • 3
1 Solution
 
b0lsc0ttCommented:
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
 
starbonesAuthor Commented:

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
 
b0lsc0ttCommented:
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
 
b0lsc0ttCommented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now