Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

OnBeforeUnload / window.open

Posted on 2006-10-25
1
Medium Priority
?
1,555 Views
Last Modified: 2008-01-25
I am trying to open a popup in the onbeforeunload event of an aspx page. It works fine the first time but will not do it after that. I put an alert in so I know the onbeforeunload event is firing so I think my issue is with the window.open.

Here is the code I am using

StringBuilder sbConfirmExit = new StringBuilder();

sbConfirmExit.Append("<script>");
sbConfirmExit.Append("window.onbeforeunload = confirmExit;");
sbConfirmExit.Append("var postback = false; function confirmExit() { ");
sbConfirmExit.Append("if(postback == true) ");
sbConfirmExit.Append("event.cancelBubble = true; ");
sbConfirmExit.Append("else ");
sbConfirmExit.Append("OpenExitWindow();");
sbConfirmExit.Append(" }</script>");
                  
                        
this.Page.RegisterStartupScript("ConfirmClose",sbConfirmExit.ToString());
                        
StringBuilder sbOpenWindow = new StringBuilder();
sbOpenWindow.Append("<script language=\"javascript\">");
sbOpenWindow.Append("var NewWindow;");
sbOpenWindow.Append("function OpenExitWindow(){alert('innewwindow');");
sbOpenWindow.Append("NewWindow = window.open(\"Exit.aspx\",\"win\",\"target=_blank,location=yes,status=yes,toolbar=yes,menubar=yes,scrollbars=yes,titlebar=yes,resizeable=yes\");");
sbOpenWindow.Append("} </script>");
                              
this.Page.RegisterStartupScript("OpenWindow", sbOpenWindow.ToString());

Thank you
0
Comment
Question by:HydeNSeeka
[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
1 Comment
 
LVL 6

Accepted Solution

by:
davbouchard earned 2000 total points
ID: 17805214
It works for me. Could it be a popup blocker?
I also noticed you have a } in your second script before the </script> that doesn't seem to belong there.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

715 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